One, the creation and transformation of tuples:
Ages = (one, 22, 33, 44, 55) Ages = Tuple (11
ages = tuple ([]) # string, list, dictionary (default is key)
- Tuples can basically be viewed as non-modifiable lists
- Tuple (iterable), which can hold all data types that can be iterated
The immutability of the tuple
such as: T = (+, ' Jesse ', (' Linuxkernel ', ' Python '), [+, ' Jesse '])
The element number 17 in the tuple T and the string ' Jesse ' as well as the tuple (' Linuxkernel ', ' Python ') itself are immutable elements, so it is not updatable in tuples, but the list contained therein [N, ' Jesse '] itself belongs to a mutable element, so:
>>> T = (+, ' Jesse ', (' Linuxkernel ', ' Python '), [+, ' Jesse ']) >>> t (+, ' Jesse ', (' Linuxkernel ', ' Pytho n '), [+, ' Jesse ']) >>> t[0] = 18Traceback (most recent call last): File "<stdin>", line 1, in <modul E>typeerror: ' Tuple ' object does not support item assignment>>> t[3][17, ' Jesse ']>>> t[3][0] = 21> >> T (+, ' Jesse ', (' Linuxkernel ', ' Python '), [+, ' Jesse '])
Three, meta-group common operations
#count (self,value) #功能: Counts the number of elements in the current tuple Tup = (55,77,85,55,96,99,22,55,) Tup.count #返回结果: 3 element ' 55 ' appears 3 times in tuple Tup # Index (self, value, Start=none, stop=none) function: Gets the index value of the element in the tuple, and for the repeating element, the default gets the index value of the first element from the Left Tup = (55,77,85,55,96,99,22,55,) Tup.index (55) Results returned: 0tup.index (85) return Result: 2tup.index (55,2,7) return result: 3
Tuple source Code
Python basic data type--tuple