標籤: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 (序列)