We use cookies to ensure you get the best experience on our website. Please review our Privacy Policy to learn more.
The None
keyword is used to define a null
variable or an object. In Python, None
keyword is an object, and it is a data type of the class NoneType
.
We can assign None
to any variable, but you can not create other NoneType
objects.
Note: All variables that are assigned
None
point to the same object. New instances ofNone
are not created.
The syntax of None
statement is:
None
Note:
None
statement supports bothis
and==
operators.
None
is not the same as False
.None
is not 0.None
is not an empty string
.None
to anything will always return False
except None
itself.
None
using is
operator:
# Declaring a None variable var = None if var is None: # Checking if the variable is None print("None") else: print("Not None")
None
using ==
operator:
# Declaring a None variable var = None if var == None: # Checking if the variable is None print("None") else: print("Not None")
None
object:
# Declaring a variable and initializing with None type typeOfNone = type(None) print(typeOfNone)
None
with None
type:
# Comparing None with none and printing the result print (None == None)
None
with False
type:
# Comparing none with False and printing the result print(None == False)
None
with empty string
:
# Declaring an empty string str = "" # Comparing None with empty string and printing the result print (str == None)