Python uses the None
to represent the absence of a value or a null value.
The None
is often used to indicate that a variable or expression has no meaningful value.
The None
is commonly used in Python when we need to represent a missing or undefined value.
It's an important concept for handling default or initialise variables, as well as indicating the absence of a result or a condition.
You can assign the value None
to a variable to indicate that it has no initial value.
x = None
Here, we declare a variable x
and assign None
to the variable x
.
A function that does not have a specific return value, then it returns a None
by default.
def python_function():
pass
print(python_function())
None
In the above example, a function with no return statement. After calling this function, we got the None
value in the output.
You can use the is
operator to check if a variable or expression is equal to None
.
x = None
if x is None:
print("x is none.")
x is none.
In the above example, we checked x
variable is None
or not, if x is None
, then print x is none
. Here is the output, you can see the text is printed, and x is none
.