Skip to main content

What are Tuples? (Locked Lists)

A Tuple is almost identical to a List, with just one simple rule: Once created, a Tuple cannot be changed!

  • A List uses square brackets [] → Items can be added, removed, or changed.
  • A Tuple uses parentheses () → Items are locked and permanent.

1. Real-Life Metaphor: Open Box vs Locked Box

Think of data containers in real life:

  • List [ ] = An Open Storage Box
    You can put items in, take items out, or replace an item with a new one whenever you want (like a Shopping Cart).

  • Tuple ( ) = A Sealed Glass Case
    Once items are placed inside, they are locked forever. Nobody can alter, add, or delete any item (like your Date of Birth or Aadhar Card Number).

Quick Comparison: List vs Tuple

LIST [ ] (CHANGEABLE)
fruits = ["apple", "banana"]
fruits[0] = "mango" # Allowed!
TUPLE ( ) (LOCKED)
fruits = ("apple", "banana")
fruits[0] = "mango" # Error! Locked

2. Creating and Reading Tuples

Creating a tuple is as simple as using round brackets ():

# A tuple storing fixed screen resolution (width, height)
resolution = (1920, 1080)

# A tuple storing a date of birth (day, month, year)
dob = (25, "December", 2000)

# Reading items works starting at index 0 (just like lists!)
print(dob[0]) # Output: 25
print(dob[1]) # Output: December

3. Why Do We Need Tuples?

Beginners often ask: "If Lists can do everything, why do we need Tuples?"

  1. Data Safety: Important data (like User ID, Coordinates, or Passwords) won't be accidentally modified or deleted by mistake.
  2. Faster Performance: Python processes Tuples faster than Lists because their size is fixed.

4. Single-Item Tuple Tip

If you want to create a tuple with only 1 item, you must add a comma , after the item:

# Without comma: Python thinks it is a normal number
my_num = (5)
print(type(my_num)) # Output: <class 'int'>

# With comma: Python knows it is a Tuple!
my_tuple = (5,)
print(type(my_tuple)) # Output: <class 'tuple'>

Quick Summary

  • Tuple Definition: An ordered, immutable (read-only) sequence enclosed in round parentheses (...).
  • Immutability Protection: Items inside a tuple cannot be added, removed, or modified after creation.
  • Single-Item Tuple: Requires a trailing comma (item,) so Python distinguishes it from standard math parentheses.
  • Lists vs. Tuples: Use Lists [...] for dynamic collections; use Tuples (...) for fixed, protected records (e.g., GPS coordinates, RGB values).

What's Next?

Next, let's learn how to assign multiple tuple values to multiple variables at once using Packing & Unpacking!