English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Python basic tutorial

Python flow control

Fonctions en Python

Types de données en Python

Python file operations

Python objects and classes

Python date and time

Advanced knowledge of Python

Python reference manual

Usage and examples of Python tuple()

Built-in functions of Python

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

In Python, tuples are immutable sequence types. Using tuple() is one of the methods to create tuples.

The syntax of tuple() is:

tuple(iterable)

tuple() parameters

  • iterable(Optional)-Iterable (list, range, etc.) or iterator object

If the iterable is not passed to tuple(), this function will return an empty tuple.

Example: Create a tuple using tuple()

t1 = tuple()
print('t1 =, t1)
# Create a tuple from a list
t2 = tuple([1, 4, 6})
print('t2 =, t2)
# Create a tuple from a string
t1 = tuple('Python')
print('t1 =,t1)
# Create a tuple from a dictionary
t1 = tuple({1: 'one', 2: 'two'})
print('t1 =,t1)

Output result

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

Recommended reading:Python tuple

Built-in functions of Python