by nickles · 4y ago · 0 comments
This one liner works:
if expr: x = 1
> Or how about mutable default values in function paramters? That makes a lot of sense...This can be helpful under certain circumstances (e.g. memoization) [1]. The linked article also points out that it can be useful for rebinding global names in optimized code.
[0] https://stackoverflow.com/a/1145781
[1] https://web.archive.org/web/20200221224620id_/http://effbot....
But PEP8 and now the all-too-popular Black formatter disallow this. I think it's fine.
The momoization/optimization point is exactly the opposite of what should be a default use case for a beginner friendly language. And I highly doubt this mutable default design was intentional for these purposes. They are footguns.