Difference Between List and Tuple

// Quick Answer
  • Lists are mutable (can be changed).
  • Tuples are immutable (cannot be changed).
  • Lists are used for dynamic data.
  • Tuples are used for fixed data.
  • Tuples are faster and more memory efficient.

What is List and Tuple?

In Python, both list and tuple are used to store multiple values in a single variable. They are ordered collections, but the key difference is whether the data can be modified or not.

Key Differences

  • Mutability β€” List can be changed, tuple cannot be changed after creation.
  • Syntax β€” List uses [ ], tuple uses ( ).
  • Performance β€” Tuple is faster because it is immutable.
  • Memory β€” Tuple uses less memory than list.
  • Use case β€” List for changing data, tuple for fixed data.

Example

example.py
# List (mutable)
my_list = [10, 20, 30]
my_list.append(40)
my_list[0] = 99

# Tuple (immutable)
my_tuple = (10, 20, 30)
# my_tuple[0] = 99  ❌ Error: cannot modify tuple

Memory and Performance

Tuples are stored in a fixed memory structure, which makes them more efficient. Lists require extra memory because they are designed to grow and shrink dynamically.

πŸ’‘ Important insight

Tuples are not just β€œsmaller lists” β€” they are optimized for fixed data storage.

Real-world example

  • πŸ›’ List = Shopping cart (items can be added or removed)
  • 🎟 Tuple = Aadhaar number / coordinates (fixed and cannot change)

When to use what?

Use List when:

  • You need to modify data
  • You need to add or remove items frequently
  • Example: student names, shopping items

Use Tuple when:

  • Data should not change
  • You want better performance and safety
  • Example: coordinates, fixed configuration values

Common mistake

Beginners often think tuple is just a β€œread-only list.” That is not fully correct. The real difference is that tuples are designed for immutability at the system level.

Summary

Lists are flexible and dynamic, while tuples are fixed and optimized. Use lists for changeable data and tuples for constant data to write efficient Python programs.