Life goes beyond Python!
The previous blog share with you a list of the drudgery in Python. There are many things we can do to modify the list.
What we are going to share today is another sequence, but it cannot be modified, that is, the tuple, which is enclosed in parentheses .
Separate values with commas, automatically creating tuples
>>>1, 2, 3(1, 2, 3)
Empty tuple
>>>()()
A tuple that contains a value that must be comma-
>>>3333>>>(33)33>>>33,(33,)
tuple function
Basically the same as the list function: Takes a sequence as an argument and converts it to a tuple, or returns if the argument is a tuple.
>>>tuple([123])(123)>>>tuple(‘abc‘)(‘a‘‘b‘‘c‘)>>>tuple((123))(123)
Meta-Group Index
>>>x = 1, 2, 3>>>x[1]1
tuple Shards
End of Shard or tuple
>>>x = 1, 2, 3>>>x[0:2](1, 2)
why the existence of tuples
1 can be used as keys in the map
2 many built-in functions and methods use tuples as return values
Python Basics-Immutable sequences: tuples