Python boolean if statement | Basics

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 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 and suggestions on this Python boolean topic.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

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

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.