Python Tutorial Python Advanced Python References Python Libraries

Python None Keyword



The Python None keyword is used to define a null value. It is not same as 0, False or an empty string. Comparing None with anything else will return False. In fact, None is an object in Python, and it is a data type of class NoneType.

Syntax

None          

Example:

It can be assigned to any variable as shown in the example below.

x = None
print (x)

x = 10
print(x)

The output of the above code will be:

None
10

Example: Comparing with None

In the example below, None is compared None using if-else block.

x = None
 
if x is None:
  print("x is None.")
else:
  print("x is not None.")

The output of the above code will be:

x is None.

Example: Comparing with empty string

Here, None is compared with empty string and it returns False.

MyString = ""
 
if MyString is None:
  print("MyString is None.")
else:
  print("MyString is not None.")

The output of the above code will be:

MyString is not None.

❮ Python Keywords