Skip to content

How to check NoneType in Python

Use is operator to check NoneType in Python, like the below code. Since None is the sole singleton object of NoneType in Python, we can use is operator to check if a variable has None in it or not.

if variable is None:

Note: if you declare two or more variables with the value None, they will refer to the same NoneType object.

How to check NoneType in Python

A simple example code determining a variable’s type is NoneType in Python.

x = None

if x is None:
    print(x)
    print(type(x))
else:
    print("X is not None")

Output:

How to check NoneType in Python

Do comment if you have any doubts or suggestions on this Python NoneType 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.

1 thought on “How to check NoneType in Python”

Leave a Reply

Your email address will not be published. Required fields are marked *