Re:Anti-Patterns in Python Programming
by CognitiveLens on Thursday July 10, 2014 @12:10PM
(#8015439)
I believe the former is more idiomatic, but I don't have a reference.
You want to explicitly check against `None` so that you're not overwriting all falsey values of `val` - even though you should generally try to enforce argument types, your second example would cause unexpected behavior in some cases, particularly those that have non-falsey 'default' assignments
Re:Anti-Patterns in Python Programming
by Dylan16807 on Wednesday July 09, 2014 @09:56PM
(#8013191)
I'm well aware of that way to do it, but it doesn't excuse a different way being unintuitive.
if val is None: val = []
or the more idiomatic python way: