Loading lesson path
Overview
None is a special constant in Python that represents the absence of a value.
NoneType, and
NoneType object.
None to indicate "no value" or "not set".
x = None print(x)to see the type of a None value.
Assign and print the data type of a
x = None print(type(x))None, use the identity operator is or is not
Use the identity operator is for comparisons with
Formula
result = None if result is None:print("No result yet")
else:
print("Result is ready")Similar example, but using is not instead:
Formula
result = None if result is not None:print("Result is ready")
else:
print("No result yet")False in a boolean context.
print(bool(None))Functions that do not explicitly return a value return None by default.
def myfunc():Formula
x = 5 x = myfunc()print(x)