Python full-stack development: python tuple, python Development Group tuple
Tuples
What is a tuples: "tuples are an unchangeable List" (not a list, just to facilitate memory)
Purpose: it is used to store multiple values. It can only be read but cannot be assigned twice.
Format: Use commas to separate each element in parentheses ().
Eg:
tuples = ('a','b','c','d')
Common Operations of tuples
Generate a simple tuples
Tuples = tuple (range (5) print (tuples) # result (0, 1, 2, 3, 4)
Len (tuple)
# Calculate the length of tuples = (0, 1, 2, 3, 4) print (len (tuples) # result: 5
In and not in
# In and not intuples = ('A', 'B', 'C', 'D') print ('A' in tuples) # result: trueprint ('Z' in tuples) # result: Falseprint ('x' not in tuples) # result: Trueprint ('D' not in tuples) # result: False
Values of tuples
# Tuples = ('A', 'B', 'C', 'D') item = tuples [0] print (item) # result: aitem = tuples [2] print (item) # result: c # while loop c = 0 while c <len (tuples): print (tuples [c]) c + = 1 # for Loop for item in tuples: print (item)
Shard of tuples
The slicing operation of tuples is not described here. Please refer to the slicing of strings.
Full-stack Python development: python string Slicing