Python basics-Introduction to tuples of immutable sequences
More than Python!
In the previous blog, I shared with you the effort and list in Python. We can modify the list through many operations.
Another sequence is to be shared today, but it cannot be modified, that is, the tuples, which areEnclose in parentheses.
Values are separated by commas (,), and tuples are automatically created.
>>>1, 2, 3(1, 2, 3)
Empty tuples
>>>()()
The tuples that contain a value must contain commas (,).
>>>3333>>>(33)33>>>33,(33,)
Tuple Function
Basically the same as the list function: uses a sequence as a parameter and converts it to a tuple. If the parameter is a tuple, it is returned as is.
>>>tuple([1, 2, 3])(1, 2, 3)>>>tuple('abc')('a', 'b', 'c')>>>tuple((1, 2, 3))(1, 2, 3)
Tuples Index
>>>x = 1, 2, 3>>>x[1]1
Tuples
Whether the parts are finished or the tuples
>>>x = 1, 2, 3>>>x[0:2](1, 2)
Why are there tuples?
1 can be used as a key in ing
2 many built-in functions and methods use tuples as return values