tuple is another ordered list, also known as "tuple".If a tuple is used to represent the names of the classmates in the class, the tuple is used to represent the following:
t = ('Zhang San', 'Li Si', 'Wang Wu')
tuple is very similar to list, the only difference between creating a tuple and creating a list is that () is used instead of [], tuple cannot be changed after it is createdWell, tuple has no methods for inserting and removing elements.
The method of obtaining tuple elements is exactly the same as that of list. We can normally use t[0], t[-1] and other index methods to access elements, but cannot assign them to other elements.
tuple can contain 0, 1 and any number of elements, tuple containing multiple elements has been created in the above example.
A tuple of 0 elements is an empty tuple, which is directly represented by ():
t = ()print(t)
Execute the above code, the output result is:
()