Computer >> Computer tutorials >  >> Programming >> Python

How we can use Python Tuple within a Tuple?


Tuple is defined as an ordered collection of any Python objects enclosed in parentheses. Hence, a tuple can very well be one of the items in the collection.

>>> t1=(1,(4, 5, 6),2,3)
>>> t1
(1, (4, 5, 6), 2, 3)

In this example, item at index number 1 in t1 is a tuple itself. Hence it can be retrieved using the index as −

>>> t1[1]
(4, 5, 6)

Further items of enclosed tuples can also be retrieved using their internal index

>>> t1[1][1]
5