You Can't Handle the Truth!

I got a chance to review some other people’s Python code recently, and there’s one comment I almost always have to give, which is:

This is a companion discussion topic for the original entry at

Great blog post, can you please make the text and the code font the same size. It makes reading on mobile easier

Interesting and good to know. However, in the (probably most common) case of using None as a default value for a kwarg, you're often then setting some mutable default that you couldn't set in the signature, like "if x is None: x = {'foo':'bar'}" Therefore the shortcut version would be "if not x". In what situation would that be dangerous? "not None", "not []", "not {}" etc... all reliably resolve to True.

FYI, Personally I always us "is (not) None" but when explaining to newbies it's always good to give as much context as possible, i.e. "Yes 'if not x' will work reliably but you should get in the habit of doing 'if x is None' so that you'll also write 'if x is not None' where it really makes a difference"