
July 23, 2018
5:01 p.m.
On Sun, Jul 22, 2018 at 11:54:19AM +1000, Steven D'Aprano wrote:
In my opinion, writing
expression if expression is None else default
is the *opposite* of Pythonic, it is verbose and the DRY violation is inelegant (as well as inefficient). I'd much rather use:
expression ?? default
although with PEP 572 approved, there is an alternative:
temp := expression if temp is None else default
I was mistaken. That would need to be written as: temp if (temp := expression) is None else default which is obscure enough for me to prefer the ?? syntax again. -- Steve