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:
pythontst = 3
Let's check if it has the value None:
pythonif tst == None:
print('+++')
else:
print('---') # will this work
You can also use the keyword is when checking:
pythonif tst is None:
print('+++')
else:
print('---') # will this work
To find out that a variable is NOT None, not is added to the condition:
pythonif tst is not None:
print('+++') # this will work
else:
print('---')
Задание 1
Given a variable:
pythontst = 10
Check that it is equal to None.
Задание 2
Given a variable:
pythontst = 'abc'
Check that it is not equal to None.