Logical Operators in Python

In all programming languages you will find logical operators. Logical operators are used to combine conditional statements. There are three logical operators in Python.

Now, let’s see the logical operators in Python:

Operator Description Example
and Returns True if both statements are true x < 5 and  x < 10
or Returns True if one of the statements is true x < 5 or x < 4
not Returns False if the result is true not(x < 5 and x < 10)

Python Code with logical operators:

x=5
y=6
if x<=5 and y<=5:
    print("inputs are ok")
else:
    print("inputs are not ok")

Output:

inputs are not ok

In this tutorial, I have shown logical operators in Python. Hope you have enjoyed the tutorial. If you want to get updated, like my facebook page http://www.facebook.com/freetechtrainer and stay connected.

Add a Comment