python none code example
Example 1: python 2.7 check if variable is none
>>> NoneType = type(None)
>>> x = None
>>> type(x) == NoneType
True
>>> isinstance(x, NoneType)
True
Example 2: pythonhow to check if value is None
var = None
if var is None:
print("var is None")
else:
print("var is not None")
var = "sometext"
if var is None:
print("var is None")
else:
print("var is not None")
Example 3: None python
>>> def has_no_return():
... pass
>>> has_no_return()
>>> print(has_no_return())
None
>>> import re
>>> match = re.match(r"Goodbye", "Hello, World!")
>>> if match is None:
... print("It doesn't match.")
"It doesn't match."