MCQ Hive stays free thanks to ads. Please disable your ad blocker for this site so content and features keep working.
Data Types
Python Built-in Types
Beginner
Q
Given t = ([1],), what happens with t[0].append(2)?
AIt succeeds and t becomes ([1, 2],)
BAttributeError
Ct becomes ([1], 2)
DTypeError, because tuples are immutable
Correct Answer:
A. It succeeds and t becomes ([1, 2],)
Explanation:
The tuple's references cannot change, but a mutable object it contains can still be modified.
ALSO KNOW (related points):
• What is type((5)) in Python? → int
• Given L = [0, 1, 2, 3, 4, 5], what are L[::-2] and L[1:-1:2]? → [5, 3, 1] and [1, 3]
• Does a Python dict preserve the order in which keys were inserted? → Yes, guaranteed by the language since Python 3.7