Home Tutorials Python Tutorial Tuples
Tuples

Tuples


Definition: Tuples are ordered collections used to store multiple items in a single variable. They are very similar to lists, but with one major difference: they are immutable, meaning they cannot be changed after creation.

Why: Beginner Python guides usually teach tuples right after lists to highlight the difference between data that can change (mutable) and data that must stay constant (immutable). They are used to protect data from accidental modifications.

Syntax

tuple_name = (item1, item2, item3)

Example

days = ("Mon", "Tue", "Wed")
print(days)
print(days[1])

Explanation

  • Parentheses: Tuples are defined using round brackets ( ) instead of square brackets.
  • Indexing: Just like lists, items inside a tuple have an order and can be accessed using their index number starting at 0 (so days[1] prints "Tue").
  • Immutability: If you try to add or change an item (e.g., days[0] = "Sunday"), Python will throw an error.

Key Notes

  • Tuples allow duplicate values (e.g., you can have ("Mon", "Tue", "Mon")).
  • Because they cannot change, tuples are faster and use less memory than lists.
  • To create a tuple with only one item, you must include a trailing comma (e.g., my_tuple = ("apple",)), otherwise Python will mistake it for a regular string or number.
Example

🏋️ Test Yourself With Exercises

Take our quiz on Tuples to test your knowledge.

Exercise »