Skip to main content
How To Check None Value In Python

How To Check None Value In Python

in this post, We’ll learn how to check None value in python. A null value is defined by None. It differs from an empty string, False, or a zero. It’s a data type from the NoneType object class. The None is a special singleton object.

You can also checkout other python tutorials:

We can check the type of None:

print(type(None))

Output:

<class 'NoneType'>

Using is Operator

The “is” operator is a Python built-in that determines whether both operands refer to the same object.

data = None

if data is None:
    print("The data variable has None Value")
else:
    print("It does not have None value")

Output:

The data variable has None value

We have defined a variable and checked the variable using the if statement with the is the operator. If it is None, the if statement is executed; otherwise, the else statement is executed.

Leave a Reply

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