Editor

Predict the Output: Single Item Tuple

Beginner · Predict the output · from Python Tuples: When and Why to Use Immutable Sequences

From the lesson: Python Tuples: When and Why to Use Immutable Sequences

Think about GPS coordinates. A location like (40.7128, -74.0060) represents New York City. If you accidentally changed one of those numbers, the location would point somewhere completely different. Some data simply should not change after you create it.

Read the lesson

Read this code carefully. What will it print? Think about what makes something a tuple versus just a number in parentheses.

Type the exact output.

a = (5)
b = (5,)
print(type(a).__name__)
print(type(b).__name__)

More Tuples exercises

All Python exercises · 50 practice problems · Data Structures quiz