[Python-ideas] Fwd: Null coalescing operator

Guido van Rossum guido at python.org
Sun Sep 11 21:11:29 EDT 2016


On Sun, Sep 11, 2016 at 6:00 PM, David Mertz <mertz at gnosis.cx> wrote:
>     None if a is None else a.foo

This is the crux of the matter to me. It's just too verbose, and the
`if` and `else` keywords are lost in the noise of all the other words
on the line. Plus the big win when it applies) is that if `a` is in
fact something more complex, like `f(a)`, repeating it twice sounds
like a performance penalty, and that's where `f(a)?.foo` really
shines.

-- 
--Guido van Rossum (python.org/~guido)


More information about the Python-ideas mailing list