Introduction
In Python, None
is a special constant that represents the absence of a value or a null value. It is an object of its own data type, the NoneType
, and it is not equivalent to any other value or data type.
The NoneType
The type of None
is NoneType
, which is a built-in type in Python.
NoneType
has only a single value, None
. This makes None
a unique and singular entity in Python, and it is always the same object in memory.
Example:
print(type(None))
Output:
<class 'NoneType'>
Assigning None
You can assign None
to a variable to indicate that it is empty or has no value.
Example:
my_variable = None print(my_variable)
Output:
None
Checking for None
You can check if a variable is None
using the is
operator, which checks for identity (i.e., if two references point to the same object).
Example:
my_variable = None print(my_variable is None)
Output:
True
Summary & Reference for the Python None Value
None
is a special constant in Python that signifies the absence of a value.
The type of None
is NoneType
. It is a built-in type in Python with None
as its only value.
print(type(None)) # --> <class 'NoneType'>
You can assign None
to a variable to indicate that it is empty or has no value.
my_variable = None print(my_variable) # --> None
To check whether a variable is None
, use the is
keyword.
my_variable = None print(my_variable is None) # --> True