tuples

  • Read only list (no add, delete, change, only read), can store a large amount of data, can index, slice (step size)
  • Often used for data that does not want to be changed by others, the elements in a tuple can be changed if there is a list of elements in the list
  • Unpacking of tuples and assigning values respectively

Tuple unpacking assignment

A,b=(1,2) # print(a,b)Copy the code

Tuples supplement

  • When there is only one element in a tuple, the tuple’s data type is the element itself, not the tuple.

    Tu =(2) print(type(tu)) <class ‘int’>

    Print (type(tu)) <class ‘list’>

    Tu =(1,1,2,32,2) t1=tu.count(1) print(t1)

    Print (t1) tu=(1,1,2,32,2)