Skip to Main Content

Python for Basic Data Analysis: 1.10 Logical operators

Get started on your learning journey towards data science using Python. Equip yourself with practical skills in Python programming for the purpose of basic data manipulation and analysis.

Logical operators 

Logical operators 

We use these operators to evaluate a statement to return either a  True  or a  False 

Operator Syntax Description Example
and x and y This returns  True  if both x and y are true

x = 10
x > 5 and x < 15

or x or y This returns  True  if either x or y are true x = 10
x > 5 or x < 2
not not x Reverses a result, so if something is  True ,
not turns it  False 
x = 10
not(x > 5 and x < 15)

Example

Exercises

Use the operators to evaluate whether these statements are  True  or   False .

Qn Equation True or False?
1 x = 200
print(x > 4 or x < 300)
 True  or   False 
2 3 != 4 and 3 < 4  True  or   False 
3 x = 200
print(not(x > 4 or x < 300))
 True  or   False