In this statement of their own level is very limited, with the blog to write in front of the public is really embarrassing in front of everyone, but out of the mix, the skin must be thick!
Python's tuples and lists are very similar, but the elements in the list are mutable objects, and tuples are immutable objects. The output of the list is surrounded by brackets, and the output of the tuple is surrounded by parentheses.
Each element of a tuple is separated by commas, so you can create a tuple with this feature:
u=1,2,3u# (a)
How to create an empty tuple, or a tuple that contains elements
empty= () one= "Hello", #注意后面的逗号
Package and sequence unpacking of tuples
For example, u=1,2,3,4 is a packaged example.
Unpack
X,y,z= (a)
X=1,y=2,z=3, it is natural that the number of values on the left side is equal to the number of tuple sequences.
Tuple method of tuples, converting a list to a tuple
>>>t=tuple ([1,2,3,4]) >>>t (1,2,3,4)
What does a tuple ("abcdef") get?
The result is (' A ', ' B ', ' C ', ' d ', ' e ')
There is no limit to the data type of elements in a tuple, but it is a number, a string, a tuple, or a list. Although the elements of a tuple are immutable, the elements in the list in the tuple are mutable.
eg
>>> eg= (1,2,3,4,[5,6]) >>> Eg[4]=[7,8]traceback (most recent call last): File "<pyshell#15 > ", Line 1, in <module> eg[4]=[7,8]typeerror: ' Tuple ' object does not support item assignment
will produce an error
>>> eg= (1,2,3,4,[5,6]) >>> eg[4].append (7) >>> eg (1, 2, 3, 4, [5, 6, 7])
Because the list is a mutable type.
Tuples and lists can be converted to each other. List () and tuple ()
A tuple of Python