Login
📚 Introduction to Python Programming
Chapters ▾
⇩ Download ▾

3.5 Tuple basics

Learning objectives

By the end of this section you should be able to

  • Describe the features and benefits of a tuple.
  • Develop a program that creates and uses a tuple successfully.
  • Identify and discuss the mutability of a tuple.

Creating tuples and accessing elements

A tuple is a sequence of comma separated values that can contain elements of different types. A tuple must be created with commas between values, and conventionally the sequence is surrounded by parentheses. Each element is accessed by index, starting with the first element at index 0.

Tuple properties

How do tuples compare to lists? Tuples are ordered and allow duplicates, like lists, but have different mutability. An immutable object cannot be modified after creation. A mutable object can be modified after creation. Tuples are immutable, whereas lists are mutable.