Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Python · Class

tuple

tuple is Python’s immutable sequence type. Create tuples with comma-separated values or tuple(iterable); they support common sequence operations and can hold heterogeneous or homogeneous data.

How it works

tuple is an immutable sequence type. You can create one from an iterable, preserve the iterable's item order, access elements with normal sequence operations, and use comma-separated literals; the comma, rather than parentheses alone, determines tuple construction.

Syntax

class tuple(iterable=(), /)

Parameters

NameTypeDescription
iterableiterableOptional sequence, iterable container, or iterator whose items are copied into the resulting tuple; defaults to an empty tuple.

Returns

A tuple containing the iterable's items in the same order; with no argument, an empty tuple.

Key points

  • Tuples are ordered, immutable containers that work well for fixed-shape records with differing field types.
  • They can represent fixed collections of values of one type when mutation should be disallowed.
  • tuple(iterable) preserves both the elements and their iteration order.
  • The constructor accepts sequences, iterable containers, and iterator objects.
  • Indexing, slicing, membership checks, iteration, and other common sequence operations are available.
  • A tuple's type can be parameterized by the types of its contents.

Common mistakes

  • A singleton needs a trailing comma: (item,); (item) is just the parenthesized item.
  • Passing an existing tuple to tuple() does not create a different tuple value.

Example: Creating and using tuples

values = tuple([1, 2, 3])
record = ("Ada", 42)
singleton = ("ready",)

print(values)
print(record[0], record[1])
print(singleton)

This runnable example creates tuples from an iterable and literals, including the required trailing comma for a one-item tuple.

When to use it

Immutable heterogeneous records

Representing a fixed record such as a name-and-value pair without allowing the container structure to change.

Freezing iterable results

Converting a sequence, iterable container, or iterator into an ordered immutable sequence.

Hashable compound values

Using a fixed collection where immutability is useful for membership in sets or use as dictionary keys, subject to the contents being hashable.

Interview questions

QWhat is a tuple, and when would you use one?

tuple is an immutable sequence type, so its sequence structure cannot be changed after creation. It is commonly used for heterogeneous records or immutable homogeneous sequences.

Follow-up: Why can a tuple still contain mutable state? Because immutability applies to the tuple's item references, not necessarily to the objects referenced by those items.

QHow does tuple() construct its result?

The constructor is tuple(iterable=(), /). With no argument it creates an empty tuple; with an iterable it creates a tuple containing the iterable's items in the same order.

Follow-up: What happens when the argument is already a tuple? The documentation says it is returned unchanged.

QHow are tuple literals written?

Tuple literals can use (), a trailing comma for one item, or comma-separated items such as a, b, c. Parentheses are optional except for the empty tuple or where syntax requires disambiguation.

Follow-up: Why does f((a, b)) differ from f(a, b)? The former passes one tuple argument, while the latter passes two arguments.

  • list
  • range
  • enumerate
  • set
  • dict
  • frozenset

Source: Built-in Types. Checked 2026-10-15.