# .css-fhxb3m{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;}.css-9a49z0{margin-right:0.5rem;height:2.5rem;width:2.5rem;-webkit-flex-shrink:0;-ms-flex-negative:0;flex-shrink:0;overflow:hidden;border-radius:9999px;}  Prahlad Inala

Follow

Follow # Logical Operators in Python

·Jul 12, 2021·

## What are Logical Operators in Python?

Logical operators are used to combining 2 booleans into another boolean.

Following are the logical operators in python:

1. and
2. or
3. not

## And Operator

And operator evaluates to true if both left and right evaluate to true., else it evaluates to false.

``````x = 8
print(x > 5 and x < 10)
#True
#returns True because 8 is greater than 5 (True) AND 8 is less than 10 (True)

x = 5
print(x > 3 and x > 10)
#False
#returns False because 5 is greater than 3 (True) But 5 is not greater than 10 (False)

x = 5
print(x < 3 and x > 10)
#False
#returns False because 5 is not less than 3 (False) AND 5 is not greater than 10 (False)
``````

## OR Operator

Or operator evaluates to True if either left or right side evaluates to True., else it evaluates to false.

``````x = 5
print(x > 3 or x > 10)
#True
#returns True because 5 is greater than 3 (True), even 5 is not greater than 10(False)

x = 5
print(x < 3 or x < 10)
#True
#returns True because 5 is less than 3 (False), even 5 is less than 10 (True)

x = 5
print(x < 3 or x > 10)
#False
#returns False because 5 is less than 3 (False), even 5 is not greater than 10 (False)
``````

## Not Operator

Not operator evaluates to the opposite boolean given a boolean.

``````x = 5
print(not(x > 3 and x < 10))
#False
# returns False because not is used to reverse the result

x = 5
print(not(x < 3 and x < 10))
#True
# returns True because not is used to reverse the result
``````