Python example for None watchword: Here, we will figure out how to check whether a variable contains a worth or not?
As we have talked about in the past post (Python None watchword), that “None” is a catchphrase which can be utilized to appoint an invalid an incentive to a variable or to check whether a variable contains any worth or not.
Example:
Here, we have 3 factors a, b and c, and is being allowed with “Hello“, b is being relegated with “None” and c is being doled out with 10.
We are trying whether factors have a worth or None, on the off chance that they have values, we are printing their qualities.
# python code for not None test
# variable 1 with value
a = "Hello"
# variable 2 with None
b = None
# variable 3 with value
c = 10
# performing is not None test
if a is not None:
print("value of a: ", a)
else:
print("\'a\' contains None")
if b is not None:
print("value of b: ", b)
else:
print("\'b\' contains None")
if c is not None:
print("value of c: ", c)
else:
print("\'c\' contains None")
Output:
value of a: Hello
'b' contains None
value of c: 10