Skip to content

If true Python concept | Example code

  • by

If-statement” is a special way to control the flow of code. It will compute if a statement is true or false in Python. The true condition will execute the code and the false condition won’t execute the code.

Example If true Python

True and False are Booleans in Python. The if conditional statements use Boolean math to compute their Boolean state.

if True:
    print("True!")

if False:
    print("True!")

Output:

If true Python

If with condition

var = 1

if var == 1:
    print("Var value is 1")

Output: Var value is 1

Multiple conditions

a = 1
b = 1

if a == 1 and b ==1 :
    print("a and b value is 1")

Output: a and b value is 1

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

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 *