What is correct syntax to create Python tuples?

PythonServer Side ProgrammingProgramming

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,)
raja
Published on 29-Dec-2017 06:12:31
Advertisements