# tuple# tuple and list are very similar, but the tuple cannot be modified once initialized classmates = (' Michael ', ' Bob ', ' Tracy ') print ("Classmates (tuple)", Classmates) # defines an empty Tuplet = () print ("t (empty tuple)", T) # defines a tuple with only 1 elements, plus a comma t = (1,) # A tuple is also added with a comma when displaying a tuple of only one element. So as not to misunderstand the bracket print in the mathematical sense ("t (tuple only), T) # When defining a tuple with only one element, if you do not add a comma, the system will assume that the parentheses in the mathematical formula T = (1) print (" t (not a tuple,is a brackets) ", T) # a" mutable "tuple# a tuple starts to point to the list and does not change to another list, so the so-called" invariant "of a tuple is to say that each element of a tuple, pointing to never changing # that points to ' a ', cannot be changed to point to ' B ', Pointing to a list cannot be changed to point to other objects, but the list itself is mutable! t = (' A ', ' B ', [' A ', ' B ']) t[2][0] = ' X ' t[2][1] = ' Y ' Print ("t (change list of the tuple)", T)
A tuple in Python