tuple
Create a tuple from the items of an iterable.
Python 3.13
tuple([iterable])- [ ]optional part
- iterable
- The items of the new tuple; without it, an empty tuple is created.IterableOptional
Return value
A new tuple with the items in the same order.
Examples
Tuple from a list
Python 3.13
print(tuple([1, 2, 3]))(1, 2, 3)
Tuple of string characters
Python 3.13
print(tuple('hi'))('h', 'i')Details
For a tuple, tuple returns the same object without copying, since a tuple cannot be changed anyway. A one-item tuple is written with a comma, (1,), while (1) is just a number in parentheses.
