Skip to content

None in Python

  • by

Python None is a special object of the NoneType class. It is used to define a null variable or an object. Syntax of None as follows:

None

Using Python None as an initial value for a variable

state = None

Note: None is not the same as False or empty string or 0. If the function doesn’t return anything that means its None in Python.

None in Python

Simple example code.

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

print(None)
print(type(None))

Output:

None in Python

Checking if a variable is None using is operator:

x = None

if x is None:
    print("Variable value is None")
else:
    print(x)

Output: Variable value is None

if you use equality (==) or is operator to compare None with None, you’ll get the result of True:

print(None == None)
print(None is None)

Python Null and None Keyword

There’s no null in Python; instead, there’s None.

Do comment if you have any doubts or suggestions on this Python basic topic.

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