About python tuple operations

About tuple:

  1. Tuples and lists are similar, but the data tuple can not be amended.
  2. Tuple is a pair ()

Tuple operations:

  1. Tuples can not be amended so few operations tuple
  2. Define the empty tuple (a tuple because once created, the data can not be modified, thus creating little empty tuple)
    info_tuple = ()

     

  3. Element defines a tuple
    info_tuple = (20,)

    When you create a tuple of elements behind the elements should be added a comma, if you forget to add the words, not the creation of a tuple but a variable, such as:

  4. Yuan Group Length
    info_tuple = (1, 2, 5) 
    only (info_tuple)

     

  5. Value, whichever index
    = info_tuple (. 1, 2,. 5 ) 
    
    # value 
    Print (info_tuple [. 1 ]) 
    
    # fetch index 
    Print (info_tuple.index (. 1))

     

  6. Statistical same element occurrences
    info_tuple = (1, 2, 5, 2)
    print(info_tuple.count(2))

     

  7. List and tuple into each other

 

Guess you like

Origin www.cnblogs.com/icebluelp/p/11615686.html