Tuple tuples
Definition: The element within the container is immutable, the container is a tuple
Use () to represent a tuple
After the tuple is initialized, its elements are not modifiable and cannot be deleted
To create a tuple:
1, x = (obj1, obj2, Obj3,...) or x = Obj1, Obj2, Obj3, ...
1 x = (1, 2, 3, 4, 5)2print(x, type (x))3 ---> (1, 2, 3, 4, 5) < class ' tuple '>
2, x = () Create an empty tuple
1 x = ()2print(x, type (x))3 ---> () <class' tuple'>
Built-in functions:
1. Len (tuple) Gets the length of a tuple
2, Max (tuple) & min (tuple) Gets the maximum and minimum values for a tuple
3. Tuple (SEQ) converts a list to a tuple
1 list = [1, 2, 3, 4, 5]2 tup = tuple (list)3print(tup) 4 ---> (1, 2, 3, 4, 5)
Tuple tuples, as a sequence container, are the same as list lists, with:
1. Slicing operation
2. Connection +
3. Copy *
4. Member detection in & not in
5. For ... in ... Looping through
Tuple derivation formula:
tuple = (n for n in list if judging condition)
1 tup1 = (1, 2, 3, 4, 5)2 for in tup1)3print (Tup2, type (tup2)) 4 ---><generator object <genexpr> at 0x05672e70> <class' Generator'>
The tuple derived from the tuple is actually a generator
Python Base---container tuple