What is the most pythonic way to check if a variable is not None? [closed]
The two have a different meaning, the first one won't be triggered by most falsy objects (''
, False
, 0
, etc.), the second will. So the logic is different. If you really care about not being None
, use the second one.
x = False
if x:
print('one')
if x is not None:
print('two')
output:
two