Facebook Page Twitter Page LinkedIn Page
× Python Tutorial Python Advanced Python Resources Python Libraries


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 below example.

x = None
print (x)

x = 10
print(x)

The output of the above code will be:

None

10

Example: Comparing with None

In the below example, 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