The characteristic of a tuple is that its elements are immutable (immutable), and once set, it cannot be modified using an index.
>>> t1=1,2,3,4,5 #给Tuple赋值 >>> t1[0] #按照索引读取Tuple元素1 > >> u1=t1, (2,3,4,5,6) #tuple可以嵌套 >>> U1 ((1, 2, 3, 4, 5), (2, 3, 4, 5, 6)) >>> U1[1] (2, 3, 4, 5, 6) > >> U1[-1] (2, 3, 4, 5, 6) >>> u1=t1, (2,3,4,5,6),3>>> U1 ((1, 2, 3, 4, 5), (2, 3, 4, 5, 6), 3) >> > list1=[' we ', ' the ', ' North ']>>> list1[' we ', ' the ', ' North ']>>> u1=t1,list1>>> U1 ((1, 2, 3, 4, 5), [' we ', ' the ', ' North '] >>> list1[-1]= ' Toronto ' #元组内的元素是可变的, so you can modify the inner element to update tuples >>> U1 ((1, 2, 3, 4, 5), [' we ', ' the ', ' Toronto ']) >>> len (u1) 2>>> myList = [1,2,3,4,5,6,7,8,9,10]>>> Mytuple = ( 1,2,3,4,5,6,7,8,9,10) >>> mylist= (2,) #初始化一个元素的时候, need to take comma>>> myList (2,) >>> mylist[0]2 >>> Mylist[1]traceback (most recent): File ' <stdin> ', line 1, in <module>indexerror:tuple Index out of range>>> len (myList) 1
Instructions for Python tuple tuples