Python Booleans

You can use this data type to represent boolean values. Internally Python represents True as 1 and False as 0.

The only allowed values for this data type are: True and False.

>>> b=True
>>> print(type(b))
<class 'bool'>

For Instance:

print(5 > 4) ==> True
print(5 == 4) ==> False
print(5 < 4) ==> False

You can get boolean value using a condition in an if statement, Python returns True or False.

x = 100
y = 55
if y > x:
    print("y is greater than x")
    print("y is not greater than x")

y is not greater than x

Evaluate Values and Variables using bool()

You can evaluate values using bool() function. It returns either True or False.

  • All string is True, except empty strings.
  • All number is True, except 0.
  • All list, tuple, set, and dictionary are True, except empty ones.
a = "Python"
b = 5

While declaring values using bool() function, mostly it returns True values. Only few values are False. Let’s have a look on them.


Functions returns a Boolean

Functions can be created to return a Boolean Value.

def boolFunction():
    return True

Previous Read : Python Variables

Share on:

Ravindra Kumar

Hi, This is Ravindra. I am founder of TheCodeCloud. I am AWS Certified Solutions Architect Associate & Certified in Oracle Cloud as well. I am DevOps and Data Science Enthusiast.

Recommended Reading..

1 thought on “Python Booleans”

  1. Pingback: Python Operators

Leave a Comment