English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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)
iterable(Optional)-Iterable (list, range, etc.) or iterator object
If the iterable is not passed to tuple(), this function will return an empty 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