Python Reference Library →

Python bool() Function – Convert to Boolean

Let’s look at bool() function – convert to boolean

  1. Notice

    bool() converts a value to True or False according to truth testing. Zero and empty collections are false.

  2. Try

    Follow the example, change its sample, and compare what happens.

  3. Check

    Explain the result and test your understanding.

Watch how it works

Focus on how the names, objects, and calculations change. We’ll inspect the printed output in the next section.

Explore the idea

Follow the code and watch its state change. Guided simulation.

Code
Python
number = 3
print(bool(number))
Live state

Top-level scope

number→Object 1
Object 1 · int3
This step

bool() converts a value to True or False according to truth testing. Zero and empty collections are false.

Picture bool() function – convert to boolean

bool() converts a value to True or False according to truth testing. Zero and empty collections are false.

Image brief

Alt text
A diagram for Python bool() Function – Convert to Boolean. Instructions: number = 3 print(bool(number)). Displayed result: True. The final example bindings are number --> object 1 (int). object 1: 3
Image generation prompt
Create a clean educational illustration for a Python programming lesson titled "Python bool() Function – Convert to Boolean". Teaching focus: bool() converts a value to True or False according to truth testing. Zero and empty collections are false. Depict exactly the relationships and labels in this reference diagram: EXAMPLE INSTRUCTIONS number = 3 print(bool(number)) | v DISPLAYED RESULT True FINAL BINDINGS number --> object 1 (int) object 1: 3 Use a flat vector style, generous spacing, clear arrows and legible labels, with a restrained blue/teal palette on a plain background. The diagram must explain the programming idea accurately. Do not depict variables as boxes containing copied objects when they share a reference. Avoid mascots, decorative screenshots, logos, gradients and extra text. Landscape composition, approximately 3:2, suitable for a course card. Accessible description: A diagram for Python bool() Function – Convert to Boolean. Instructions: number = 3 print(bool(number)). Displayed result: True. The final example bindings are number --> object 1 (int). object 1: 3

Follow the execution

Choose a different sample input, then follow every step through to the output. Before revealing it, predict what the program will display.

Execution workspace

Choose a sample and follow its execution. Guided simulation.

Code
Python
number = 3
print(bool(number))
Live state

Top-level scope

number→Object 1
Object 1 · int3
This step

The example has finished. Compare the final output with the values and references above.

Terminal
Output
True

What do you expect this program to print?

What does this example display?

number = 3
print(bool(number))
What does this example display?
Choose one answer. You can try again.

Answer and explanation

True

Follow the printed values in order. The output is: True

More examples and reference

Python bool() Function

The bool() function in Python is used to convert a value to a Boolean – either True or False. It’s a very useful function when you want to check if a value is considered "truthy" or "falsy".

Syntax

bool(value)

Parameters:

  • value – Any Python object (optional)

Returns:

  • True or False depending on the "truthiness" of the object

Example 1: Convert Numbers to Boolean

print(bool(10))     # True
print(bool(0))      # False

Example 2: Convert Strings to Boolean

print(bool("hello"))  # True
print(bool(""))       # False

Example 3: Convert Lists and Other Containers

print(bool([1, 2, 3]))  # True
print(bool([]))         # False
print(bool({}))         # False
print(bool(None))       # False

Truthy vs Falsy in Python

These are treated as False when passed to bool():

  • 0
  • 0.0
  • "" (empty string)
  • [] (empty list)
  • {} (empty dict)
  • set() (empty set)
  • None

Everything else is considered True.

Use Case: Check if Input is Empty

user_input = input("Enter your name: ")
if bool(user_input):
    print("Hello,", user_input)
else:
    print("You didn't enter anything!")

Common Mistakes

  • Assuming "False" (string) is False – it’s actually True!
  • Forgetting that None is always False

Interview Tip

Understanding what values are considered falsy is important in conditions, loops, and clean code. Python often uses if some_list: instead of if len(some_list) > 0:

Summary

  • bool() converts a value to True or False
  • Falsy values: 0, "", [], {}, None
  • Truthy values: everything else

Practice Problem

Write a program to check if the user entered any text. If not, ask them to try again.

text = input("Enter something: ")
if bool(text):
    print("You entered:", text)
else:
    print("Please enter some text.")

What to remember

Connect what you noticed in the example with the idea below.

Remember

bool() converts a value to True or False according to truth testing. Zero and empty collections are false.

Watch out for this idea

Every non-empty value is False.

This is the misconception to avoid.

Reference checks are optional and do not count toward course progress.

    Reference library →