Introduction to Sequences
Sequence is a combination of ordered elements
A sequence can be multiple elements, or an element may not have
There are 2 types of sequences: tuple ( fixed value table ), List (table)
D:\python\python_day>Pythonpython3.5.2 (V3.5.2:4DEF2A2901A5, June, 22:18:55) [MSC v.1900 64bit (AMD64)] on Win32type" Help","Copyright","credits" or "License" forMore 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): File"<stdin>", Line 1,inch<module>TypeError:'tuple'Object does notSupport Item Assignment>>> b[0]=2>>>Print(B,type (b)) [2,'OLIVER', 2.9] <class 'List'>
Through the above code can be found:
1.tuple is the inclusion of its elements through "()", and the list contains its elements through "[]".
Elements in 2.List can be modified, but the elements in a tuple cannot be modified.
3.type (object name) can see the data type of the object.
--------------------------------------------------------------------------------------------------------------- -----
References to elements
Sequence element subscript is starting from 0
Print (a[1]) OLIVER
Empty sequence
>>> c=[]print(c) []
A sequence as an element of another sequence
>>> d=['QIN', [1,'YUE'] Print([0][1])print(d[0][1]) I
Python sequence (sequence)