Booleans represent one of two values: True or False. Comparisons return booleans.
Almost any value can be evaluated with bool(). These are False:
False, None, 0, 0.0, "", [], (), {}, set()
Everything else is True.
True, False and truth values.
✍️ 3 exercises + code challenge in this lessonBooleans represent one of two values: True or False. Comparisons return booleans.
Almost any value can be evaluated with bool(). These are False:
False, None, 0, 0.0, "", [], (), {}, set()
Everything else is True.
Mastering Python Booleans helps you write clean and reliable Python code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
print(10 > 9)
print(10 == 9)
print(bool("Hello"), bool(15))
print(bool(""), bool(0), bool([]), bool(None))
cart = []
if not cart:
print("Your cart is empty")
Check what you learned in “Python Booleans”.
Write the boolean value for "yes".
is_open =
Which of these is False when converted with bool()?
Print the result of bool([]).
Free sign-in required · Google login available
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services