Skip to main content
Python offers two primary sequence data types: lists and tuples. While lists are mutable—allowing you to modify their data by deleting items or appending new ones—tuples are immutable, meaning their data remains constant once created.
Remember: Unlike lists, tuples cannot be modified after creation. This property makes them useful in scenarios where a constant set of values is required.

Creating and Using Tuples

A tuple is defined using parentheses or simply comma-separated values. Below is an example of creating and printing a tuple:
Much like lists, tuples support data access through loops and slicing. For instance, you can iterate through a tuple using a for loop:
Attempting to modify a tuple, however, results in errors. Unlike lists, tuples do not support methods like append, nor can you assign a new value to an individual element:

Tuple Characteristics

  • Immutable Structure: Once a tuple is created, its contents cannot be changed.
  • Versatile Storage: Tuples can store elements of different data types including integers, strings, variables, and even other tuples.
For example, you can combine multiple data types into a single tuple:

Single-Element Tuples

Creating a tuple with a single element requires a trailing comma to distinguish it from a regular parenthesized expression:

Comparing Lists and Tuples

While lists offer flexibility through mutability, tuples provide a reliable structure for fixed data. A quick comparison: That’s it for now! Dive into some hands-on practice with tuples in this lesson to reinforce your understanding and explore their practical applications.

Watch Video