About
Kodeclik is an online coding academy for kids and teens to learn real world programming. Kids are introduced to coding in a fun and exciting way and are challeged to higher levels with engaging, high quality content.
Popular Classes
Scratch Coding
Minecraft Coding
TinkerCAD
Roblox Studio
Python for Kids
Javascript for Kids
Pre-Algebra
Geometry for Kids
Copyright @ Kodeclik 2025. All rights reserved.
Python’s if not operator tests if some condition is not true and can be a succinct way to describe some types of program logic. It is useful when a variable records a certain condition but the conditional tests for the negation of that condition.
Here is a simple example of Python’s if not operator:
This results in:
The expression following the not need not be boolean. It can be any list or string. Note that an empty list or empty string will evaluate to False and any other value will evaluate to be True.
Consider the following program:
This outputs:
On the other hand, with the below program:
we will get:
The same logic applies to lists:
will give:
On the other hand, with the below program:
we get:
Similar to strings and lists, the if not can be used with other iterables like dictionaries and tuples. In all these cases, it makes for more readable code.
Interested in more things Python? See our blogpost on Python's enumerate() capability. Also if you like Python+math content, see our blogpost on Magic Squares. Finally, master the Python print function!
Want to learn Python with us? Sign up for 1:1 or small group classes.
is_it_raining = False
if (not is_it_raining):
print("We can play Tennis!")
We can play Tennis!
customer_name = "Mickey Mouse"
if (not customer_name):
print("Customer Name not found")
else:
print("Customer Name is available")
Customer Name is available
customer_name = ""
if (not customer_name):
print("Customer Name not found")
else:
print("Customer Name is available")
Customer Name not found
mylist = []
yourlist = ['a',1,2]
if (not mylist):
print("mylist is empty")
else:
print("mylist is not empty")
mylist is empty
mylist = []
yourlist = ['a',1,2]
if (not yourlist):
print("yourlist is empty")
else:
print("yourlist is not empty")
yourlist is not empty