Bird
0
0

Consider this code:

hard📝 Application Q9 of 15
Python - Conditional Statements
Consider this code:
value = 0
if value:
    print('True')
else:
    print('False')

What will it print and why?
A'False' because 0 is treated as False in condition
BError because 0 is not boolean
C'True' because 0 is a number
DNothing, code does not run
Step-by-Step Solution
Solution:
  1. Step 1: Understand truthiness of 0 in Python

    In conditions, 0 is treated as False.
  2. Step 2: Determine which block runs

    Since value is 0 (False), else block runs and prints 'False'.
  3. Final Answer:

    Prints 'False' because 0 is falsy in if condition. -> Option A
  4. Quick Check:

    0 is falsy in if conditions [OK]
Quick Trick: 0 is False in if conditions [OK]
Common Mistakes:
MISTAKES
  • Assuming 0 is True because it's a number
  • Expecting error due to type

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes