Python None Keyword

Python None Keyword

The None keyword is used to define a null value, or no value at all.

None is not the same as 0, False, or an empty string. None is a data type of its own (NoneType) and only None can be None.


Assigning None

You can assign None to any variable.

Assigning None Example

x = None
print(x)
print(type(x))

Checking for None

The best practice for checking if a variable is None in Python is to use the is identity operator, rather than the == equality operator.

Using `is None`

x = None

if x is None: print("x has no value") else: print("x has a value")

Exercise

?

What is the recommended way to check if a variable val is strictly None?