1>>> NoneType = type(None)
2>>> x = None
3>>> type(x) == NoneType
4True
5>>> isinstance(x, NoneType)
6True
1# How to check if a variable is None
2
3var = None
4# variable is None in this example
5
6if var is None:
7 # if var is None
8
9 print("var is None")
10 # code...
11
12else:
13 # if var is not None
14
15 print("var is not None")
16 # code...
17
18# result of above example "var is None"
19
20
21
22var = "sometext"
23# variable is not None in this example
24
25if var is None:
26 # if var is None
27
28 print("var is None")
29 # code...
30
31else:
32 # if var is not None
33
34 print("var is not None")
35 # code...
36
37# result of above example "var is not None"