[Python-ideas] Null coalescing operator
Chris Angelico
rosuav at gmail.com
Fri Sep 9 16:06:27 EDT 2016
On Sat, Sep 10, 2016 at 6:01 AM, Arek Bulski <arek.bulski at gmail.com> wrote:
> Sometimes I find myself in need of this nice operator that I used back in
> the days when I was programming in .NET, essentially an expression
>
>>>> expr ?? instead
>
> should return expr when it `is not None` and `instead` otherwise.
You can use 'or' for this, as long as you're okay with other falsey
values being treated the same way. In a lot of cases, this isn't a
problem.
However, even if this is implemented, it would be in an expression
context, so 'raise' would never work. For that, I'd just use the
explicit statement form.
ChrisA
More information about the Python-ideas
mailing list