None keyword in Python | Example code

“None keyword” is used to define variables or objects without any values. If you assign a None value to a variable or object then it same as a null value, or no value at all.

var = None

Note: The “None” is not the same as zero, False, or an empty string. It is an object of the class NoneType.

Example None keyword in Python

Simple example code. Some time in development assigning a value of None to a variable is one way to reset it to its original, empty state.

var = None

print(var)
print(type(var))

Output:

None keyword in Python

Another example

If there are two variables assign the None value then variables point to the same object. The address of both the variables is the same.

var1 = None
var2 = None

print(id(var1))
print(id(var2))

Output:

140707342354448
140707342354448

Do comment if you have any doubts and suggestions on this Python None tutorial.

Note: IDE: PyCharm 2021.1.3 (Community Edition)

Windows 10

Python 3.7

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.