0
0
Pythonprogramming~20 mins

Tuple vs list comparison in Python - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
๐ŸŽ–๏ธ
Tuple vs List Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ“ Predict Output
intermediate
2:00remaining
Output of comparing tuple and list with same elements
What is the output of this code snippet?
Python
print((1, 2, 3) == [1, 2, 3])
ATrue
BTypeError
CFalse
DNone
Attempts:
2 left
๐Ÿ’ก Hint
Think about how Python compares different data types.
โ“ Predict Output
intermediate
2:00remaining
Result of comparing nested tuple and list
What will this code print?
Python
print((1, [2, 3]) == (1, [2, 3]))
ATrue
BFalse
CTypeError
DNone
Attempts:
2 left
๐Ÿ’ก Hint
Look inside the tuple elements carefully.
โ“ Predict Output
advanced
2:00remaining
Comparing tuple and list with same elements but different order
What is the output of this code?
Python
print((1, 2, 3) == [3, 2, 1])
ATrue
BFalse
CTypeError
DNone
Attempts:
2 left
๐Ÿ’ก Hint
Order matters in sequences.
โ“ Predict Output
advanced
2:00remaining
What happens when comparing tuple and list with mutable elements?
What will this code print?
Python
a = [1, 2]
b = (1, 2)
print(a == b)
a[0] = 3
print(a == b)
ATrue\nFalse
BFalse\nTrue
CTrue\nTrue
DFalse\nFalse
Attempts:
2 left
๐Ÿ’ก Hint
Check the values before and after changing the list.
๐Ÿง  Conceptual
expert
2:00remaining
Why does comparing tuple and list with same elements return True?
Why does Python return True when comparing a tuple and a list with the same elements?
ABecause although tuples and lists are different types, Python compares their elements and considers them equal if they match.
BBecause tuples are immutable and lists are mutable, so Python raises an error.
CBecause Python compares only the first element and they differ in type.
DBecause Python converts tuples to lists before comparing and the conversion fails.
Attempts:
2 left
๐Ÿ’ก Hint
Think about how Python treats different data types in equality checks.