来源于:视频《Python3入门与进阶-第三章》
Python3入门与进阶-第三章链接
Python的基本数据类型
#布尔类型,非0都是True
bool(2) #True
bool(2.2) #True
bool(-1.1) #True
bool(0) #False
#空值都是False
bool('') #False
bool([]) #False
bool({}) #False
bool(None) #False`
#注意三引号 与 转义字符
'''\nhello world\nhello world\nhello world'''
'\nhello world\nhello world\nhello world' #面试里考题
print('''\nhello world\nhello world\nhello world''')
hello world
hello world
hello world #编程中用到
'''
hello world
hello world
'''
'\nhello world\nhello world\n'
'''hello world
hello world'''
'hello world\nhello world'
'hello\
world'
'helloworld' # \ 左上右下为转义字符
#转义字符在输出地址栏的应用
print('c:\northwind\northwest')
c:
orthwind
orthwest
print('c:\\northwind\\northwest') #转义再转义=原始
c:\northwind\northwest
print(r'c:\northwind\northwest')
c:\northwind\northwest
字符串的运算
#字符串的拼接
'hello' +'world' #'helloworld'
#步长问题
"hello world"[0] #'h'
"hello world"[3] #'l'
"hello world"[4] #'o'
"hello world"[-1] #'d' 倒数第一个
"hello world"[-3] #'r' 倒数第三个
'hello world'[0:4] #'hell'
'hello world'[0:-1] #'hello worl'
'hello world'[0:-3] #'helle wo'
"hi python c# javascript php ruby"[3:] #'python c# javascript php ruby'
"hi python c# javascript php ruby"[-4:] #'ruby'