Python sequence (序列)

來源:互聯網
上載者:User

標籤:ast   ace   2.7   log   amd   ack   port   []   strong   

序列簡介

sequence 是一組有序元素的組合

序列可以是多個元素,也可以一個元素都沒有

序列有2種:tuple(定值表)、List(表)

D:\python\Python_Day>pythonPython 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license" for more information.>>> a=(1,‘OLIVER‘,2.7,False)>>> print(a,type(a))(1, ‘OLIVER‘, 2.7, False) <class ‘tuple‘>>>> b=[1,‘OLIVER‘,2.9]>>> print(b,type(b))[1, ‘OLIVER‘, 2.9] <class ‘list‘>>>> a[0]=2Traceback (most recent call last):  File "<stdin>", line 1, in <module>TypeError: ‘tuple‘ object does not support item assignment>>> b[0]=2>>> print(b,type(b))[2, ‘OLIVER‘, 2.9] <class ‘list‘>

通過以上代碼可以發現:

1.tuple是通過“()”包含其元素,List是通過“[]”包含其元素。

2.List中的元素是可以進行修改的,但是tuple中的元素師不可以進行修改的。

3.type(對象名) 可以看出該對象的資料類型。

--------------------------------------------------------------------------------------------------------------------

元素的引用

序列元素下標是從0開始的

>>> print(a[1])OLIVER

空序列

>>> c=[]>>> print(c)[]

一個序列作為另外一個序列的元素

>>> d=[‘QIN‘,[1,‘YUE‘]]>>> print([0][1])>>> print(d[0][1])I

 

Python sequence (序列)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.