Tuples-a list with shackles
1. The use of tuples is similar to the list, but the list permissions are large, the list can be arbitrarily deleted or modified elements, but tuples can not be changed
2. Create and change tuple basic operations:
Created: tuple1= (' 1 ', ' 2 ', 3 ...) Note that the key to creating a tuple is "," comma, tuple1= (1) This is not a tuple, tuple1= (1,) or tuple1=1, is a tuple; Create an empty tuple tuple1= (); Tuple1 =1,2, 3 This is also a meta-group
Access tuples: tuple1[1], tuple1[2:], tuple1[:], Tuple1[:3]
Different from list: cannot be changed, cannot be assigned
3. Update and delete tuples:
1) Slice the tuple, add a new element, and then splice the slices
such as: t= (' 11 ', ' 22 ', ' 333 ', ' ha ha '), insert ' whining ' after the second element
t = T[:2] + (' whining ',) + t[2:]
2) Delete the tuple:
Delete element in tuple:tuple1 = tuple1[:1]+tuple1[2:] Delete second element
Delete entire tuple: del t
4. Which operators can be used on tuples:
1) Stitching tuple1 = tuple1[:1]+ (' whining ',)
2) Repeat operator: 8* (8,) 8 Repeat 8 times
3) relational operator:> < =
4) member operators: in and not in
5) logical operator: and OR
Python Learning meta-group