Tuples in Python

    Kedar Kabra4 min readUpdated

    A tuple is an ordered collection of items, just like a list — but with one big difference: once created, a tuple cannot be changed. You write a tuple using round brackets:

    point = (3, 5)            # a tuple of two numbers
    colours = ("red", "green", "blue")
    
    print(point[0])           # 3  (indexing works like lists)
    print(colours[1])         # green
    

    That "can't be changed" quality (called immutability) is exactly why tuples are useful. Let's explore.

    Creating tuples

    You can create a tuple with or without brackets — commas are what make it a tuple:

    t1 = (1, 2, 3)
    t2 = 1, 2, 3              # also a tuple (this is "packing")
    print(type(t2))          # <class 'tuple'>
    
    # A single-item tuple NEEDS a trailing comma
    one = (5,)               # this is a tuple
    not_a_tuple = (5)        # this is just the number 5!
    print(type(one), type(not_a_tuple))   # <class 'tuple'> <class 'int'>
    
    # An empty tuple
    empty = ()
    

    That single-item rule trips up almost everyone: (5) is just 5 in brackets. You need the comma: (5,).

    Accessing and slicing

    Tuples support indexing and slicing exactly like lists:

    days = ("Mon", "Tue", "Wed", "Thu", "Fri")
    
    print(days[0])      # Mon  (first item)
    print(days[-1])     # Fri  (last item)
    print(days[1:3])    # ('Tue', 'Wed')  (a slice)
    

    Tuples are immutable

    This is the defining feature. You cannot change, add, or remove items:

    point = (3, 5)
    # point[0] = 10     # ERROR: 'tuple' object does not support item assignment
    

    If you need to "change" a tuple, you create a new one instead. This immutability makes tuples safe to use as fixed records — like coordinates, RGB colours, or a date — that should never accidentally change.

    Want to learn this properly?

    Join the waitlist for our courses — beginner-friendly, project-first classes in Jalgaon.

    Browse courses

    Tuple unpacking

    One of the nicest tuple features is unpacking — assigning each item to its own variable in one line:

    person = ("Asha", 21, "Jalgaon")
    
    # Unpack all three items at once
    name, age, city = person
    print(name)     # Asha
    print(age)      # 21
    print(city)     # Jalgaon
    
    # Swap two variables instantly using tuples
    a, b = 1, 2
    a, b = b, a
    print(a, b)     # 2 1
    

    This is also how a function returns multiple values — they come back as a tuple you can unpack:

    def min_max(numbers):
        return min(numbers), max(numbers)   # returns a tuple
    
    low, high = min_max([4, 9, 1, 7])
    print(low, high)    # 1 9
    

    A practical example

    # Store student records as tuples (fixed, won't change)
    students = [
        ("Asha", 85),
        ("Ravi", 72),
        ("Meena", 91),
    ]
    
    # Unpack each tuple in the loop
    for name, score in students:
        print(f"{name} scored {score}")
    

    Common mistakes

    • Forgetting the comma in a one-item tuple: (5) is the number 5, not a tuple. Write (5,).
    • Trying to modify a tuple: Assigning t[0] = ... raises a TypeError. Tuples are read-only; build a new tuple instead.
    • Unpacking the wrong number of items: a, b = (1, 2, 3) raises a ValueError because there are three values but two names. Counts must match (or use *rest).
    • Confusing tuples and lists: Use a tuple when the data shouldn't change (a coordinate, a record). Use a list when you'll add, remove, or modify items.
    • Mixing up brackets: Tuples use (), lists use [], and dictionaries/sets use {}. Easy to swap by accident.

    FAQ

    Why use a tuple instead of a list? Tuples are immutable, which signals "this data is fixed" and prevents accidental changes. They're also slightly faster and can be used as dictionary keys (lists cannot).

    Can a tuple contain a list? Yes. A tuple's structure is fixed, but if it holds a mutable item like a list, that inner list can still be changed. The tuple itself just can't swap which objects it points to.

    How do I count or find items in a tuple? Tuples have two methods: .count(value) counts occurrences and .index(value) finds the first position of a value.


    Tuples are one of Python's core collections. Compare them with Lists in Python and learn key-value storage in Dictionaries in Python. Browse everything on the Python learning hub.

    Want to learn this properly? Join the waitlist for our Python course — taught in Jalgaon, beginner-friendly.

    Want to learn this properly?

    Join the waitlist for our courses — beginner-friendly, project-first classes in Jalgaon.

    Browse courses
    Kedar Kabra

    Instructor, Infoplanet

    Kedar Kabra teaches Python at Infoplanet, helping beginners become confident programmers through hands-on, project-first practice.

    Related guides