[Python-ideas] Null coalescing operators
Chris Angelico
rosuav at gmail.com
Sun Sep 20 11:38:18 CEST 2015
On Sun, Sep 20, 2015 at 5:31 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> Technically, x.y x[y] and x(y) aren't operators, but for the sake of
> convenience I'll call them such. Even though these are binary operators,
> the ? only shortcuts according to the x, not the y. So we can call
> these ?. ?[] ?() operators "pseudo-unary" operators rather than binary
> operators.
That's how all Python's short-circuiting works - based on the value of
what's on the left, decide whether or not to evaluate what's on the
right. (Well, nearly all - if/else evaluates the middle first, but
same difference.) This is another form of short-circuiting; "x[y]"
evaluates x, then if that's None, doesn't bother evaluating y because
it can't affect the result.
ChrisA
More information about the Python-ideas
mailing list