What is syntax of tuple declaration in Python?

PythonServer Side ProgrammingProgramming

A tuple is a comma separated sequence of items. The sequence can be optionally put inside parentheses.

>>> t1=(1, "Ravi", 23, 546)
>>> t1
(1, 'Ravi', 23, 546)
>>> type(t1)
<class 'tuple'>
>>> t1=1, "Ravi", 23, 546
>>> t1
(1, 'Ravi', 23, 546)
>>> type(t1)
<class 'tuple'>

Parentheses are essential if a null tuple or tuple with one element has to be created

>>> a=()
>>> a
()
>>> type(a)
<class 'tuple'>
>>> a=(1,)
>>> a
(1,)
>>> type(a)
<class 'tuple'>
raja
Published on 02-Jan-2018 19:05:57
Advertisements