PCEP-30-02 · Question #279
What is the expected output of the following code? print(not 0) print(not 23) print(not '') print(not 'Peter') print(not None)
The correct answer is D. 1 | True 2 | False 3 | True 4 | False 5 | True. Option D is correct because Python's not operator returns True for falsy values and False for truthy values - and 0, '' (empty string), and None are all falsy in Python, so not flips them to True, while 23 and 'Peter' are truthy, so not returns False. Option A incorrectly marks…
Question
Options
- A1 | False 2 | False 3 | True 4 | False 5 | True
- B1 | True 2 | False 3 | False 4 | False 5 | True
- C1 | False 2 | False 3 | False 4 | False 5 | False
- D1 | True 2 | False 3 | True 4 | False 5 | True
How the community answered
(54 responses)- A2% (1)
- B6% (3)
- C9% (5)
- D83% (45)
Explanation
Option D is correct because Python's not operator returns True for falsy values and False for truthy values - and 0, '' (empty string), and None are all falsy in Python, so not flips them to True, while 23 and 'Peter' are truthy, so not returns False.
Option A incorrectly marks lines 1 and 3 as False, confusing not 0 and not '' - both falsy values that should yield True. Option B gets line 3 wrong, treating '' as truthy (it's not - empty strings are falsy). Option C marks every result as False, which would only be correct if all values were truthy.
Memory tip: Think "ZONE" - Zero, Omitted (empty string/list/dict), None, and False itself are Python's core falsy values; not applied to any of them produces True. If the value has "something in it" (a non-zero number, a non-empty string), not returns False.
Community Discussion
No community discussion yet for this question.