Question 46
What is the output of (1, 2) + (3, 4) in Python?
The + operator on tuples performs tuple concatenation, returning a new single tuple containing all combined elements.
What is the output of (1, 2) + (3, 4) in Python?
The + operator on tuples performs tuple concatenation, returning a new single tuple containing all combined elements.
Which of the following is true regarding frozenset in Python?
frozenset is an immutable, hashable set variant that can be used as keys in dictionaries or elements of other sets.
What is the value of x after dictionary pop:
d = {'a': 1, 'b': 2, 'c': 3}
x = d.pop('b') + len(d)d.pop('b') removes key 'b' and returns value 2. Remaining dict d has length 2. 2 + 2 = 4.
What is the output of bool({}) and bool((0,))?
An empty dictionary {} is falsy (bool({}) is False). A non-empty single-element tuple (0,) is truthy (bool((0,)) is True).
Which of the following data structures in Python maintain unique elements without duplicates?
set, frozenset, and dict keys automatically enforce unique element/key constraints. Lists can contain arbitrary duplicates.