If is true Python concept | Example code

In Python If it’s true, it will execute the code. If statement expressions are used True and False Booleans evolution in Python.

Example If is true Python

If you want to make sure that foo really is a boolean and of value True, use the is the operator. Always use is with the built-in constants True, False, and None.

foo = True
if foo is True:
    print(True)

Output:

If is true Python

Do comment if you have any doubts and suggestions on this Python basic 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.