What is the result of the following Python snippet: `bool(0) or bool('False')`?

Answer and explanation

Correct answer: A. `True`

  1. Step 1: Evaluate `bool(0)`: integer 0 is falsy, so `bool(0)` evaluates to `False`.
  2. Step 2: Evaluate `bool('False')`: any non-empty string in Python is truthy, so `bool('False')` evaluates to `True`. `False or True` evaluates to `True`.
Answer
`True`.
Why not the others: '`False`' assumes the literal string 'False' evaluates to false boolean; '`0`' is short-circuited; '`None`' is not returned by logical boolean operators.

Practise more Python Programming, Data Structures, Algorithms, Networks and Cybersecurity.

Free questions with an explanation for every one, and full timed Saudi Secondary School Certificate mock tests.

What is the result of… | Saudi Secondary School Certificate