2.資料型別和變數
阿新 • • 發佈:2018-11-06
1.整數
1 100 -100 299
使用type(100)打印出資料的型別
print(type(100))
<class 'int'>
2.浮點數
3.1415 -0.999 26.0
使用type(3.1415)打印出資料型別
print(type(3.1415))
<class 'float'>
3.字串
a.字串以'或“括起來
b.特殊字元要使用轉義字元\
c.\t表示製表符 , \n表示換行,要列印\本身也需要使用\進行轉義
d.如果字串中帶有很多特殊字元,使用r""格式,r""格式中字元不轉義
f.'''xxx'''
print(type('I love python'))
print('abcd \\')
print('abcd\te\nf')
print(r'abcd\te\nf')
print('''
i
love
python
''')
<class 'str'>
abcd \
abcd e
f
abcd\te\nf
i
love
python
4.布林值
a.布林值只有兩個取值:True和
b.布林變數可以進行and、or、not計算(可以&、|、^)
print(True & False)
print(True and False)
print(True or False)
print(True | False)
print(not True)
print(True^False)
False
False
True
True
False
True
5.空值
python裡的空值用None表示
print(None)
print(type(None))
None
<class 'NoneType'>
6.變數和賦值運算子‘=’
a.變數名必須是大小寫英文、數字和_的組合,且不能用數字開頭
b.python是動態語言
a='i love python'
print(a,type(a))
a=123
print(a,type(a))
i love python <class 'str'>
123 <class 'int'>
7.常量
a.理論上python中不存在常量
b.約定python中的常量全部使用大寫表示