What is correct syntax to create Python tuples?

In Python, tuple object is an immutable collection of items, not necessarily of same type. Items are separated by comma and placed inside parentheses, although they are optional.

>>> T1 = (1,'one',3.45,[1,2,3])
>>> T2 = 1,2,3,4

Empty tuple object is created with nothing inside parentheses

>>> T3 = ()
>>> T3

If only one item is to be included in a tuple, an additional comma is placed after it.

>>> T4 = 10,
>>> T4 = (5,)

Updated on: 30-Jul-2019


Kickstart Your Career

Get certified by completing the course

Get Started