How do we define tuple in Python?

PythonServer Side ProgrammingProgramming

Tuple is one of the standard data types in Python. It is an immutable sequence of objects. Tuple object is created by putting one or more objects, not necessarily of same type, separated by comma. The collection can optionally be put inside parentheses.

>>> t1=1, "Ravi", 75.50, True
>>> t1
(1, 'Ravi', 75.5, True)
>>> type(t1)
<class 'tuple'>
>>> t2=(12, 12.0, 0o12, 0xc)
>>> t2
(12, 12.0, 10, 12)
>>> type(t2)
<class 'tuple'>
raja
Published on 01-Jan-2018 23:53:12
Advertisements