標籤:布爾 資料 不可變類 new long 8進位 src set .com
1.Python支援五種基本數字類型,其中有三種為整數型別
(1)整型int
(2)長整型long
(3)布爾型bool
(4)浮點型Floating-point
(5)複數complex
2.int型
標準整數類型
(1)十進位
(2) 2進位是以0b開頭的:
例如: 0b11 則表示十進位的3
(3) 8進位是以0開頭的:
例如: 011則表示十進位的9
(4) 16進位是以0x開頭的:
例如: 0x11則表示十進位的17
3.數字
4.序列
(1)字串
使用raw字串(原字串)
>>> myfile=open( r‘ c:\new\test.txt ‘,‘w‘)
使用逸出字元\
>>> myfile=open(‘c:\\new\\test.txt’,‘w’)
(2)列表
(3)元組
5.映射類型
建立字典:
>>> a = dict(one=1, two=2, three=3)
#dict()工廠函數被用來建立字典
>>> b = {‘one‘: 1, ‘two‘: 2, ‘three‘: 3}
>>> c = dict(zip([‘one‘, ‘two‘, ‘three‘], [1, 2, 3]))
>>> d = dict([(‘two‘, 2), (‘one‘, 1), (‘three‘, 3)])
>>> e = dict({‘three‘: 3, ‘one‘: 1, ‘two‘: 2})
>>> a == b == c == d == e
True
6.集合(set)
7.檔案
(1)儲存模型
? 原子儲存(scalar):
儲存單個字面對象的類型 數字、字串(字串為什麼不是容器類型?python 沒有char類型)
? 容器儲存(container):
?容納多個對象的類型 列表、元組、字典
(2) 更新模型
不可變類型:數字,字串,元組
可變類型:列表、字典
(3) 訪問模型
直接存取:數字
順序訪問: 字串、列表、元組
映射訪問:字典
Python資料類型