One, tuple characteristics
1, similar list, but immutable type, because of this, it can do a dictionary key
2, when working with a set of objects, this group is the tuple type by default
3, all the multi-object, comma-delimited, not explicitly defined by the symbol of these are the tuple type by default
>>>,'ethon'('ethon')> >> x,y=1,2>>> x, y (1, 2)>>> () # empty tuple () >>>, # A value of a tuple (42,)
Attention:
1. Cannot add element to tuple, tuple does not have append () or extend () method.
2. You cannot delete an element from a tuple, and the tuple does not have a remove () or pop () method.
3. You can find an element in a tuple, because the operation does not change the tuple.
4. You can also use the In operator to check if an element exists in a tuple.
Benefits of tuples:
1. Tuples are faster than lists, and if you define a series of constant values and all you need to do is traverse it, use a tuple substitution list
2. "write protection" of data that does not need to be changed will make the code more secure
3. tuples can be used as keys in a map, and lists cannot be
Python Foundation 5 (tuple)