← Back to Hub
Module 3 Week 9 • True/False states and Truthy/Falsy evaluations

Boolean Logic

Understand logical True and False states, verify comparisons, and evaluate truthy vs falsy values using bool().

1. What are Booleans?

In programming, you often need to know if a statement is true or false. Python has a data type called **Boolean** (bool) that can only hold one of two values: True or False.

2. Booleans from Comparisons

When you compare two values, Python evaluates the expression and returns a boolean result:

print(10 > 9)  # Output: True
print(10 == 9) # Output: False

3. Truthy vs. Falsy Values

Almost any value in Python can be evaluated as a Boolean using the bool() constructor. Python categorizes values as **Truthy** (evaluates to True) or **Falsy** (evaluates to False):

  • Falsy Values: Empty strings (""), numeric zero (0), decimal zero (0.0), and the special value None.
  • Truthy Values: Any string containing characters (even a space " "), any non-zero number, and non-empty lists/tuples.

💻 Python Code Examples

Example 1: Boolean Literals

is_active = True
is_finished = False
print(is_active, is_finished)

Description: Declares variables using boolean literals (capitalization required).

Example 2: Booleans from comparisons

x = 10
y = 20
print(x < y)  # True
print(x == y) # False

Description: Shows how comparisons return Boolean results.

Example 3: Evaluating Truthy Numbers

print(bool(100))
print(bool(-5))
# Any non-zero number is True

Description: Shows that positive and negative numbers evaluate to True.

Example 4: Evaluating Falsy Zeroes

print(bool(0))
print(bool(0.0))
# Numeric zero evaluates to False

Description: Shows that both integer and float representations of zero are falsy.

Example 5: Truthy vs. Falsy Strings

print(bool("Hello")) # True
print(bool(""))      # False (empty)
print(bool(" "))     # True (contains space)

Description: Only empty strings evaluate to False; strings containing spaces are truthy.

Example 6: Comparing Booleans Directly

a = True
b = False
print(a != b) # Output: True

Description: Compares boolean variables using comparison operators.

🧠 Active Retrieval Quizzes

Answer the following 10 multiple-choice questions to test your storage strength.

Question 1: What are the two valid values for a Boolean variable in Python?

Explanation: Python boolean values are case-sensitive and must be written as True or False.

Question 2: What is the output of print(10 == 9)?

Explanation: 10 is not equal to 9, so the statement evaluates to False.

Question 3: Which function checks the Boolean value of an object?

Explanation: The built-in bool() function evaluates variables and expressions to True or False.

Question 4: Which of these values is Falsy and evaluates to False?

Explanation: Numeric zero (0) is classified as a Falsy value in Python.

Question 5: What does the expression bool(' ') (string containing a single space) return?

Explanation: Because it contains a space character, the string is not empty and is therefore Truthy (True).

Question 6: What is the boolean evaluation of an empty string: bool('')?

Explanation: Empty strings evaluate to False.

Question 7: What does bool(0.0) return?

Explanation: Decimal float zero (0.0) is a falsy value, returning False.

Question 8: What is the output of print(5 < 10)?

Explanation: 5 is less than 10, so the expression evaluates to True.

Question 9: Is the string 'False' truthy or falsy: bool('False')?

Explanation: Because 'False' is a string containing characters, it is truthy and returns True. Only empty strings evaluate to False.

Question 10: Which of these is a truthy value?

Explanation: Any non-zero number (positive or negative) evaluates to True.

🖥️ Output Prediction Challenges

Read each code snippet carefully, analyze its execution flow, and predict the exact string result written to the console.

Challenge 1 of 5

Predict the output of the code snippet below. Type the exact output in the console.

print(10 > 5)
Console ready. Type your prediction below...
Challenge 2 of 5

Predict the output of the code snippet below. Type the exact output in the console.

print(bool(0))
Console ready. Type your prediction below...
Challenge 3 of 5

Predict the output of the code snippet below. Type the exact output in the console.

print(bool("Python"))
Console ready. Type your prediction below...
Challenge 4 of 5

Predict the output of the code snippet below. Type the exact output in the console.

print(bool(""))
Console ready. Type your prediction below...
Challenge 5 of 5

Predict the output of the code snippet below. Type the exact output in the console.

print(5 == 5.0)
Console ready. Type your prediction below...

🎮 Interactive Code Playground

Type your own Python code below and click "Run Code" to execute it instantly in your browser!

📝 Python Code Editor
Python WebAssembly runtime is unloaded. Click 'Run Code' to load.
🖥️ Output Console
Console ready.
💬 Teacher Consultation

Stuck on any concept, or want to explore an edge case? Don't hesitate to ask follow-up questions to your instructor! Active questioning helps build storage strength.

📋 Progress Status

Lesson Complete?

📌 Check the box above to mark this weekend's lesson complete. Your dashboard status ring will update automatically.