PCEP-30-02 · Question #77
Consider the following code. x = 1 x = x == x The value eventually assigned to x is equal to:
The correct answer is C. True. Option C is correct because the second line evaluates x == x, which is 1 == 1 - a comparison expression that always returns a Python bool, specifically True. While A (1) is tempting because True == 1 evaluates to True in Python (booleans are a subclass of int), the value…
Question
Options
- A1
- B0
- CTrue
- DFalse
How the community answered
(70 responses)- A3% (2)
- B10% (7)
- C80% (56)
- D7% (5)
Explanation
Option C is correct because the second line evaluates x == x, which is 1 == 1 - a comparison expression that always returns a Python bool, specifically True. While A (1) is tempting because True == 1 evaluates to True in Python (booleans are a subclass of int), the value assigned to x is the boolean True, not the integer 1. B (0) and D (False) are wrong because x == x is a reflexive equality check - any value is always equal to itself, so the result can never be False or its integer equivalent 0.
Memory tip: Whenever you see == used as an assignment value (e.g., x = a == b), remember that comparison operators in Python always produce a bool (True/False), never an integer - even if the comparison involves integers.
Community Discussion
No community discussion yet for this question.