PRO
Amogh
asked

Expert
Abhay Jajodia answered
Hi Amogh,
In Python, the not keyword is a logical operator that flips the value of a condition:
not TruebecomesFalsenot FalsebecomesTrue
So when you use if not, you're checking if a condition is not true.
Here’s a simple example:
is_raining = True
if not is_raining:
print("You don't need to bring an umbrella")
else:
print("Please bring an umbrella")
In this case, is_raining is True, so not is_raining becomes False, and the code inside the else block runs.
In short, if not is used when you want to run code only when a condition is false.
If you have more questions, I am here to help.
Python
This question was asked as part of the Getting started with Python course.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer