Skip to content

None keyword in Python | Example code

  • by

“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 assigned 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 or suggestions on this Python None tutorial.

Note: IDE: PyCharm 2021.3.3 (Community Edition)

Windows 10

Python 3.10.1

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

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading