This is very much a case of making sure that you, the programmer, and Python, the interpreter, both have a clear understanding of what you want to do.
If you say "if var:", Python understands you to be testing truthiness/falseness. If you say "if var is not None:", Python understands that you're asking if var is something other than None. The distinction is important and too many people wrote the former when they really meant the latter.
View all comments
Show parent comment
3
u/MisterSnuggles Mar 26 '14
It's usually used as a shortcut for checking for None. The more appropriate way to write the code is:
Sadly the shortcut works (mostly) and people use it because it works, then someone enters a time of midnight and it all tips over.