0Pricing
Python Academy · Lesson

Tuples and Immutability

Understand tuples, their immutability, and when to prefer them over lists.

Introduction

Tuples are ordered, immutable sequences. Once created, their elements cannot be changed.

Creating Tuples

t = (1, 2, 3) or t = 1, 2, 3 (parens optional). A single-element tuple needs a trailing comma: t = (1,).
t = (1, 2, 3)
singleton = (42,)
print(t, singleton)

All lessons in this course

  1. Creating and Accessing Lists
  2. Modifying Lists
  3. Tuples and Immutability
  4. Nested Lists and Iteration
← Back to Python Academy