Python tuple() Function

The tuple() built-in is used to create a tuple in Python.

In Python, a tuple is an immutable sequence type.

One of ways of creating tuple is by using tuple() built-in.


The syntax of tuple() is:

tuple(iterable)

tuple() Parameters

  • iterable​ (optional) - an iterable (list, range etc.) or an iterator object

If an iterable is passed, corresponding tuple is created. If the iterable is omitted, empty tuple is created.


Example: How to creating tuples using tuple()?

t1 = tuple()
print('t1=', t1)

# creating a tuple from a list
t2 = tuple([1, 4, 6])
print('t2=', t2)

# creating a tuple from a string
t1 = tuple('Python')
print('t1=',t1)

# creating a tuple from a dictionary
t1 = tuple({1: 'one', 2: 'two'})
print('t1=',t1)

When you run the program, the output will be:

t1= ()
t2= (1, 4, 6)
t1= ('P', 'y', 't', 'h', 'o', 'n')
t1= (1, 2)

Recommended reading: Python Tuples and How to use them?