Tuple tuples:
One: Basic use
1, the use: The tuple is immutable list, can save multiple values, but multiple values only take the demand, without changing the demand, then use meta-combination most reasonable
2, define the way: in () separated by commas, you can store any type of value
1Names= ('ZJ','WCL','wxx')#names=tuple (' zj ', ' WCL ', ' wxx ')2 Print(type (names))3 emphasis: Always remember to add a comma when there is only one element in the tuple4X= ('ZJ',)5 Print(Type (x))
definition Examples
3, common operation + built-in method
1 names= ('wcl','zj','wxx' )2 names[0]='wcl_xx'
1, by index value (positive fetch + reverse fetch): can only take
1 names= ('wcl','zj','wxx' ,'lxx','cxxx')2 Print (Names[1:3])
2, slicing (Gu Tou regardless of tail, step)
1 names= ('zj','WCL','wxx' ,'lxx','cxxx')2 Print (Len (names))
3. Length
1 names= ('zj','WCL','wxx' ,'lxx','cxxx')2 Print ('zj' in Names)
4, member operations in and not in
1 names= ('wcl','zj','wxx' ,'lxx','cxxx')2 for inch names: 3 Print (item)
5. Circulation
II: Summary of the type
1. Save a value or save multiple values
Multiple values can be stored, and the value can be any data type
2. Ordered or unordered
Ordered
3, variable or not variable
Not variable
The underlying principle of variable list:
Refers to the memory address of the value corresponding to the index can be changed
The underlying principle of tuples immutable:
Refers to the memory address of the value corresponding to the index can not be changed
Or conversely, as long as the memory address of the corresponding value of the index does not change, then the tuple is always unchanged
1T1 = (['a','b','C'],'WC','Office')2 3 Print(ID (t1[0]))#16357330502484 Print(ID (t1[1]))#16357330104485 Print(ID (t1[2]))#16357330105046 7T1[0][0] ='AAAA'8 Print(t1)#([' AAAA ', ' B ', ' C '], ' WC ', ' office ')9 Ten Print(ID (t1[0]))#1635733050248
examples Show
Python basic Syntax---a tuple type of data type