News for hackers. Stuff that matters.
Re:Python idioms by j_baker on Sunday June 12, 2011 @08:19PM (#2647722)
Use if not x instead of if x == 0 or if x == "" or if x == None or if x == False; likewise, if x instead of if x != 0, if x != None, etc.

Be careful with this one. "if not x" isn't necessarily the same as "if x == None". It's easy to forget that "if not x" will be true for values other than None.

Also, use "if x is None" rather than "if x == None". :-)

There are no comments on this comment yet.