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.

In this tutorial, you will learn the syntax of tuple() function, and then its usage with the help of example programs.

Syntax

The syntax of tuple() function is

tuple([iterable])

where

ParameterDescription
iterable[Optional] An iterable like list, tuple, etc.

The function returns a tuple object.

Examples

1. 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)

Output

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

2. 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)

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.