Meta-group
Tuples are immutable sequences that cannot be modified after they are created.
1 #Create a tuple that contains only one element2>>a = (3,)3>>Print(a)4(3,)5 6 #convert to tuples using tuple ()7>>atuple = Tuple ('ABCDA')8>>Print(atuple)9('a','b','C','D','a')Ten One #You can only delete an entire tuple, you cannot delete an element A>>delAtuple
Tuples are faster to access and process than lists,
If a series of constant values are defined, the main purpose is only to traverse, without modification,
Recommended use of tuples
Sequence Unpacking
1 #use sequence unpacking to assign values to multiple variables at the same time2>>x,y,z = A3>>vtuple = (false,3.5,'Exp')4>>a,b,c =Vtuple5>>Print(a,b,c)6False 3.5Exp7 8 #traversing multiple sequences at the same time9>>keys = ['a','b','C']Ten>>values = [A] One>> forKvinchZip (keys,values): A>>Print(k,v) -A 1 -B 2 theC 3 - - #Generator Derivation - #the result of the builder derivation is a generator object +>>g = ((i+2) **2 forIinchRange (10)) ->> forIinchg: +>>Print(i,end=' ') A4 9 16 25 36 49 64 81 100 121
Python basic data type--tuple