Skip to content

Python boolean if statement | Basics

  • by

Python if statement works on the boolean expression true and false statement. If true then the block will execute.

Python boolean if example

Simple example code Using a Boolean in an If-Statement in Python. Don’t forget capital T and F, it is case sensitive.

a = True
b = False

if a == True:
    print("a is true")

if a:
    print("a is true")  # shorthand of the above IF statement


Python boolean if statement

Another example

Checks if the boolean is true python with the if-else statement.

b = True
if b:
    print('b is True')
    print('b is False')

Output: b is True

Do comment if you have any doubts or suggestions on this Python boolean 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

Your email address will not be published. Required fields are marked *