3 ms·
Read my post that has the "correct answers" which show you how to do it. The key is setting the default to None and then doing something like: if val is None:
by SEJeff 12y ago
Read my post that has the "correct answers" which show you how to do it. The key is setting the default to None and then doing something like:
if val is None:
val = []
or the more idiomatic python way:
val = val or []
- Dylan16807 12y agoI'm well aware of that way to do it, but it doesn't excuse a different way being unintuitive.
- CognitiveLens 12y agoI 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