Re:WTFPython – Understanding Python through surprising snippets
by Izkata on Monday December 23, 2019 @08:04AM
(#21863340)
Amusingly, the "default parameter" version relies on a feature that also gives rise to another WTPython entry: https://github.com/satwikkansal/wtfpython/blob/master/README...
[ Parent
| on HN ]
Re:WTFPython – Understanding Python through surprising snippets
by sjagoe on Monday December 23, 2019 @08:36AM
(#21863483)
That's a different issue around default arguments that are mutable, rather than default arguments generally.
The lambda case here is more like a default argument of a constant integer (immutable) than a default that is a list, which can be altered directly by the function it's a default of.
Re:WTFPython – Understanding Python through surprising snippets
by Izkata on Monday December 23, 2019 @08:47AM
(#21863532)
The underlying feature that both rely on is that default arguments are set on function declaration instead of function call. Mutable/immutable only affects whether or not you hit the bug.