Tuples, the sequence can not be modified (the only difference from a list)
1. tuple enclosed in parentheses, separated by commas
2. If there is only one value, it must be added a comma behind
. 1 Print ((42 )) 2 Print ((42 ,)) . 3 Results: . 4 42 . 5 (42)
. 1 Print (. 3 * (40 + 2 )) 2 Print (. 3 * (40 + 2 ,)) . 3 Results: . 4 126 . 5 (42, 42, 42)
3. tuple function, one sequence as a parameter, and converts it to a tuple
1 x = tuple([1,2,3]) 2 y = tuple('abcdfgh') 3 print(x,'\n',y) 4 结果: 5 (1, 2, 3) 6 ('a', 'b', 'c', 'd', 'f', 'g', 'h')
4. Learning the meaning of tuples
4.1 yuan group used as keys in a map (as well as members of the collection), but the list does not work, meet Chapter 4
4.2 some built-in functions and the method returns tuples, tuples is required.
5. Summary
5.1 Key words / concepts - sequence, membership, methods
5.2 This chapter describes the new function
. 1 len (SEQ) # Returns the length of the sequence 2 List (SEQ) # sequence into a list . 3 max (args) # return sequence parameter set or a maximum value . 4 min (args) # returns a set of parameters and a sequence minimum 5 the reversed (seq) # lets you reverse an iterative sequence 6 sorted (seq) # returns an ordered list, which contains all the elements of the specified sequence 7 tuple (seq) # will be converted into a sequence of tuples