Boolean in Python — Python Technical Interview Questions & Answers
Boolean in Python
Boolean in Python
- Boolean is True or False — capital T and F. Comparisons create them: 3 > 2 is True. if and while read booleans. Combine with and, or, not. Many values act truthy or falsy inside if: 0, "", [], None are false; most other values are true.
- bool(x) converts using those rules. Writing true or false like JavaScript is a NameError. Viva: capital True/False, then one and/or example: True and False → False.
- Boolean in Python — output: True, False, True. Empty string is falsy.
Technical Interview Tip: Capital T/F — not true/false.
Code Examples for Boolean in Python
Example
# Boolean
print(72 >= 40)
print(bool(""))
print(bool("Asha"))
Boolean in Python — output: True, False, True. Empty string is falsy.
How to Explain Boolean in Python to an Interviewer
Explain Boolean as if you are teaching a junior — definition, then one tiny script.
True / False. and or not.
What does the example print, and why?
Boolean in Python — output: True, False, True
What mistake do freshers make with Boolean?
true/false lowercase.