About Working with Flexible Dictionaries

When you are dealing with a dictionary where certain keys and values might exist or not, and you want to have default not falsy values for certain keys, it is safer to use

1
value = data.get("key") or "default value"

instead of

1
value = data.get("key", "default value")

That's because d["key"] might equal to a legit value None, and therefore "default value" would never be assigned in the second case.

Tips and Tricks Programming Python 3