None
is similar to null in C/C++/Java, it indicates that something has no value, but there are some differences. In those languages null refers to a pointer that doesn't point to anything and it is also "0", not in Python. In Python, None
is not "0", it's an object itself. It is an object of NoneType
class and is a singleton i.e only one instance is created of None
in a program.None
is often used in absence of value in a variable, as a default value in a function parameter and is returned by default by a function if no return statement is provided or any condition is met.None
type.n = None
print(type(None)) # <class 'NoneType'>
## To check whether an object is not 'None' simply use 'if <object_name>'
if n: # same as "if n != None:"
print('will not enter this condition')
## Use 'not' to negate that condition
if not n: # same as "if n == None:"
print('will enter this condition, as n is None')