bool() in Python (original) (raw)

Last Updated : 27 Feb, 2026

bool() is a built-in function that converts a value to a Boolean (True or False). The Boolean data type is fundamental in programming and is commonly used in conditional statements, loops and logical operations. The bool() function evaluates the truthiness or falseness of a value and returns either True or False. Understanding bool() is essential for writing clean and efficient Python code.

Python `

x = bool(1) print(x) y = bool() print(y)

`

Syntax:

bool([x])

**Parameters:

**Return Value:

Truth and False Values in Python

In Python, certain values are considered "truth" or "false" based on their inherent properties. Here’s a breakdown:

**False Values:

**Truth Values:

Examples of bool()

1. Basic usage

Python `

print(bool(True))
print(bool(False))
print(bool(0))
print(bool(1))
print(bool(-1))
print(bool(0.0))
print(bool(3.14))
print(bool(""))
print(bool("Hello")) print(bool([]))
print(bool([1, 2]))
print(bool({}))
print(bool({"a": 1})) print(bool(None))

`

Output

True False False True True False True False True False True False True False

**Explanation:

2. Using bool() in conditional statement

Python `

value = 10

if bool(value): print("The value is truth.") else: print("The value is false.")

`

Output

The value is truth.

**Explanation:

3. Using bool() with Custom Objects

Python `

class gfg: def init(self, value): self.value = value

def __bool__(self):
    return bool(self.value)

obj1 = gfg(0) obj2 = gfg(42)

print(bool(obj1))
print(bool(obj2))

`

**Explanation:

Python bool() function to check odd and even number

Here is a program to find out even and odd by the use of the bool() method. You may use other inputs and check out the results.

Python `

def check_even(num): return (num % 2 == 0)

num = 8

if check_even(num): print("Even") else: print("Odd")

`

**Explanation:

  1. **num % 2 == 0: this checks if the number is divisible by 2.
  2. **bool(num % 2 == 0): converts the result into True (even) or False (odd).
  3. conditional check if True, prints "Even" otherwise "Odd".