tuple() Tuple constructor
Last updated: 2026-09-22
tuple() Tuple constructor
tuple() returns an immutable sequence; with no args returns () or an iterable's items as a tuple.
| Category | Built-in Functions |
|---|---|
| Kind | Built-in Function |
| Python Version | all |
📝 Syntax
tuple([iterable])
⚙️ Parameters
| iterable Optional | An iterable; omitted gives ().(Default:None) |
|---|
Returns:An immutable tuple of the iterable's items.
💥 Raises
TypeError— Raised when the iterable is not iterable.
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
('a', 'b', 'c')
(1, 2)
🏷️ Related Built-in Functions
💡 Related Cases
More case studies coming soon — check back later.
❓ FAQ
QWhat does tuple('abc') return?
AIt returns ('a', 'b', 'c') — converting each element of the iterable into a tuple.
QIs a tuple truly completely immutable?
AThe tuple itself is immutable (you cannot add, remove, reorder, or change elements), but if an element is a mutable object (e.g. a list) its content can still be modified, like t = ([1], 2); t[0].append(3) is legal.
QHow do I create a single-element tuple?
AUse a trailing comma: (1,) is a tuple, while (1) is just the integer 1; tuple([1]) also works.
QWhen should I choose tuple over list?
AUse a tuple when the data will not change and it must serve as a dict key or a set element (it is hashable); use a list when you need to add, remove, or modify elements.