Skip to content

Python boolean if statement | Example codes

  • by

Booleans represent one of two values: True or False. Is used in if statement in Python. If it’s true execute the block of code or else skip it.

Note: don’t forget capital T and F, it is case sensitive

Example boolean if in Python

Let’s check if the boolean is true Python

var = True
if var:
    print('var is True')
else:
    print('var is False')

Output:

Python boolean if statement

More boolean Python examples

my_boolean = 1
print(bool(my_boolean))

my_boolean = 0
print(bool(my_boolean))

my_boolean = 10
print(bool(my_boolean))

print("Coding" == "fun")

Output:

True
False
True
False

Do comment if you have any doubts or suggestions on this Python basic topic.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading