Python資料類型

來源:互聯網
上載者:User

標籤:布爾   資料   不可變類   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資料類型

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.