Python Logical Operators with Examples (Improvement Needed)
Worried About Failing Tech Interviews?
Attend our webinar on
"How to nail your next tech interview" and learn
.png)
Hosted By
Ryan Valles
Founder, Interview Kickstart

Our tried & tested strategy for cracking interviews

How FAANG hiring process works

The 4 areas you must prepare for

How you can accelerate your learnings
Register for Webinar
## Python Logical Operators
Logical operators are used to combine two or more conditions in an expression to determine if the statement is true or false. Python provides three logical operators: and, or, and not.
### And
The 'and' operator evaluates to true if both the conditions are true.
**Syntax:**
```
expression1 and expression2
```
**Example:**
```
x = 5
y = 3
if x > 4 and y > 2:
print("x and y are greater than 4 and 2, respectively")
```
In the above example, both the conditions (x > 4 and y > 2) are true, hence the output is:
```
x and y are greater than 4 and 2, respectively
```
### Or
The 'or' operator evaluates to true if either of the conditions is true.
**Syntax:**
```
expression1 or expression2
```
**Example:**
```
x = 5
y = 3
if x > 4 or y > 4:
print("x or y is greater than 4")
```
In the above example, the condition (x > 4 or y > 4) is true, hence the output is:
```
x or y is greater than 4
```
### Not
The 'not' operator evaluates to true if the condition is false.
**Syntax:**
```
not expression
```
**Example:**
```
x = 5
if not x > 4:
print("x is not greater than 4")
```
In the above example, the condition (not x > 4) is true, hence the output is:
```
x is not greater than 4
```