tuple() Builtin Function

Python – tuple()

Python tuple() builtin function returns a tuple object formed with the items of the given iterable.

If no iterable is passed as argument to tuple() function, then it returns an empty tuple object.

Syntax

The syntax of tuple() function is

tuple([iterable])

where iterable is any iterable like list, tuple, etc.

Examples

Create a Tuple from List

In the following program, we take a list of strings, and create a tuple from the elements of the given list.

Python Program

fruits = ['apple', 'banana', 'cherry']
myTuple = tuple(fruits)
print(myTuple)
Run

Output

('apple', 'banana', 'cherry')

Create an empty tuple

In the following program, we pass no arguments to tuple() function, and create an empty tuple.

Python Program

myTuple = tuple()
print(myTuple)
Run

Output

()

Summary

In this tutorial of Python Examples, we learned the syntax of tuple() function, and how to use this function to create a tuple from the items of the given iterable, with examples.