PCEP-30-02 · Question #52
What is the expected output of the following code? data1 = 'a', 'b' data2 = ('a', 'b') print(data1 == data2)
The correct answer is D. True. Option D is correct because in Python, a comma-separated assignment like data1 = 'a', 'b' implicitly creates a tuple - the parentheses are optional syntax, not what makes something a tuple. Both data1 and data2 evaluate to ('a', 'b'), so the == comparison returns True. Options…
Question
Options
- A0
- B1
- CFalse
- DTrue
How the community answered
(34 responses)- A9% (3)
- B6% (2)
- C3% (1)
- D82% (28)
Explanation
Option D is correct because in Python, a comma-separated assignment like data1 = 'a', 'b' implicitly creates a tuple - the parentheses are optional syntax, not what makes something a tuple. Both data1 and data2 evaluate to ('a', 'b'), so the == comparison returns True.
Options A (0) and B (1) are wrong because Python's comparison operators return boolean objects (True/False), not C-style integers - even though True == 1 and False == 0 in Python's type system, print() renders the boolean representation, not the integer.
Option C (False) is wrong because the two tuples are structurally identical in both type and contents, so they are equal.
Memory tip: Remember "commas make tuples, not parentheses" - parentheses are just for grouping or readability. The expression x = 1, 2, 3 is perfectly valid Python and creates a 3-element tuple.
Community Discussion
No community discussion yet for this question.