Meta-group
What is a tuple: "Tuples are an immutable list" (not lists, just for ease of memory)
Purpose: Used for storing multiple values, can only be read and cannot be assigned two times
Representation: parentheses () divide the elements with commas in the middle
eg
tuples = ('a','b','C',' D')
Common operations for tuples
To generate a simple tuple
tuples = tuple (range (5))print(tuples) #结果 (0, 1, 2, 3, 4)
Len (tuple)
# Computational element leader degree tuples = (0, 1, 2, 3, 4)print# results: 5
In and not in
#In and not inTuples = ('a','b','C','D')Print('a' inchTuples)#Result: TruePrint('Z' inchTuples)#Result: FalsePrint('x' not inchTuples)#Result: TruePrint('D' not inchTuples)#Result: False
Values for tuples
#values for tuplesTuples = ('a','b','C','D') Item=Tuples[0]Print(item)#Result: aitem = tuples[2]Print(item)#results: C#While Loopc =0 whileC <len (tuples):Print(Tuples[c]) C+=1#For Loop forIteminchtuples:Print(item)
Slices of tuples
For the slicing operations of tuples, which are not mentioned here, please refer to the slices of the string.
Python full stack development: Python string slicing
Python full stack development: Python tuple tuple