Checking for Special Values in Python
In Python, you can check whether the value of a variable is of a special data type - None, True, False.
Let us have a variable tst:
tst = 3
Let's check if it has the value None:
if tst == None:
print('+++')
else:
print('---') # will this work
You can also use the keyword is when checking:
if tst is None:
print('+++')
else:
print('---') # will this work
To find out that a variable is NOT None, not is added to the condition:
if tst is not None:
print('+++') # this will work
else:
print('---')
Given a variable:
tst = 10
Check that it is equal to None.
Given a variable:
tst = 'abc'
Check that it is not equal to None.