0
0
Pythonprogramming~20 mins

Why tuples are used in Python - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Tuple Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
๐Ÿง  Conceptual
intermediate
2:00remaining
Why choose a tuple over a list?

Which of the following is the main reason to use a tuple instead of a list in Python?

ATuples use less memory and are faster than lists.
BTuples are mutable and can be changed after creation.
CTuples allow duplicate elements while lists do not.
DTuples can only store numbers, lists can store any data type.
Attempts:
2 left
๐Ÿ’ก Hint

Think about performance and memory usage differences between tuples and lists.

โ“ Predict Output
intermediate
2:00remaining
Output of tuple immutability test

What is the output of this code?

Python
t = (1, 2, 3)
t[0] = 10
print(t)
A(1, 2, 3)
BTypeError
C(10, 2, 3)
DSyntaxError
Attempts:
2 left
๐Ÿ’ก Hint

Remember that tuples cannot be changed after creation.

โ“ Predict Output
advanced
2:00remaining
Using tuples as dictionary keys

What will be the output of this code?

Python
d = {('a', 1): 'value1', ('b', 2): 'value2'}
print(d[('a', 1)])
AKeyError
BNone
CTypeError
Dvalue1
Attempts:
2 left
๐Ÿ’ก Hint

Think about which data types can be used as dictionary keys.

๐Ÿง  Conceptual
advanced
2:00remaining
Why are tuples considered safer for fixed data?

Why might a programmer prefer tuples over lists to store fixed data like coordinates?

ABecause tuples allow changing elements easily.
BBecause tuples can only store numbers.
CBecause tuples prevent accidental modification of data.
DBecause tuples use more memory than lists.
Attempts:
2 left
๐Ÿ’ก Hint

Think about data safety and accidental changes.

โ“ Predict Output
expert
2:00remaining
Tuple unpacking with star expression

What is the output of this code?

Python
t = (1, 2, 3, 4, 5)
a, *b, c = t
print(a, b, c)
A1 [2, 3, 4] 5
B1 (2, 3, 4) 5
CSyntaxError
D1 [2, 3, 4, 5] None
Attempts:
2 left
๐Ÿ’ก Hint

Recall how star (*) unpacks multiple elements into a list.