Meta-group
A python tuple is similar to a list, except that the elements of a tuple cannot be modified. Tuples use parentheses, and the list uses square brackets.
atuple= ('hello', 77,99,18.6)print(atuple)
<1> Access tuples
atuple= ('hello', 77,99,18.6)print(atuple)Print (atuple[0])print(atuple[3])
Execution Result:
<2> Modifying tuples
Note: Changes to the tuple's data are not allowed in Python, including elements that cannot be deleted.
<3> Tuple's built-in function count, index
Index and Count are the same as in string and list usage
>>> A = (' A ',' B ',' C ',' A ',>>> a.index ( ' a ', 1, 3) # note is left closed right open interval traceback (most recent call last): File " <stdin> ", line 1, in <module> ValueError:tuple.index (x): x not in tuple>>> a.index ( ' a ', 1, 4) 3>>> a.count ( ' B ') 2>>> a.count ( ' d ') 0
Python Basics-tuples