Lesson 20 of 4050%
(Progress persistence is disabled until Phase 9)
Python
Beginner
Tuples
Store unchangeable sequences of data.
Tuples
What You’ll Learn
You’ll learn about tuples and how they differ from lists.
What is a Tuple?
Tuples are used to store multiple items in a single variable, just like lists. However, a tuple is a collection which is ordered and unchangeable (immutable). Tuples are written with round brackets ().
coordinates = (10, 20)
print(coordinates[0]) # 10
Tuples are Unchangeable
Once a tuple is created, you cannot change its values. Tuples are unchangeable, or immutable as it also is called.
coordinates = (10, 20)
# coordinates[0] = 15 # THIS WILL CAUSE AN ERROR!
When to use Tuples?
Use tuples for data that should not change throughout the life of a program, such as days of the week, or coordinates on a map. Because they are immutable, Python processes tuples slightly faster than lists.