Python If-Else Statement with AND Operator | Example code

Example code How to use AND operator to combine two basic conditional expressions in the boolean expression of the Python If-Else condition statement.

if a == 1 and b > 0:

Example If-Else Statement with AND Operator in Python

Simple python example code.

a = 1
b = 10

if a == 1 and b > 0:
    print('a is 1 and', b, 'is greater than zero.')
else:
    print('a is not 1 or', b, 'is not greater than zero.')

Output:

Python If-Else Statement with AND Operator

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.