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:
- Check if a Variable is Not Null in Python
- Python Join List Example
- How To Convert String to int and int to string
- How To Read & Update Excel File Using Python
- Convert Python Dictionary To JSON
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.