> You can say "x = 1 if expr else 2", but you cannot say "x = 1 if expr". You do a two line
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.
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.
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.