First, the introduction of the meta-group
A tuple of 1.Python is similar to a list, except that elements of a tuple cannot be modified.
2. Tuples use parentheses, and the list uses square brackets. For example:tup = (1, 2, 3, 4, 5 );
3. Tuple creation is simple, just add elements in parentheses and separate them with commas.
4. When you include only one element in a tuple, you need to add a comma after the element.
5. Tuple is similar to string, subscript index starting from 0, can be intercepted, combined and so on.
Two, the use of tuples
1. Value (using subscript)
Tup1[0]
Tup2[1:5] #顾头不顾尾, obtained is subscript 1 to subscript 4 element
2. Modify, the elements in the tuple are not modifiable, but the tuples can be joined together
Tup3 = tup1 + tup2;
3. Delete: del tup
4. Convert a list to a tuple: tuple (list)
Iii. slicing (a method of listing, string, and range values)
1.list[:3] #顾头不顾尾, if the beginning of the subscript is not written, then it is starting from the front
2.list[-1] #-1 represents the last element
3.list[1:] #如果下标不写的话, the representative takes the last
4.list[:] #开头的下标和结尾的下标都不写的话, representing the entire list
5.list[-6:-10:-1] #第二个冒号后面值代表步长, is a number of elements to take once, the step is negative, from right to left to take a value
6.list[::-1] #将列表里的元素都取出来了, but the order is reversed because the step is negative
Python tuple, List intercept