[Python-ideas] Using `or?` as the null coalescing operator

Nick Coghlan ncoghlan at gmail.com
Mon Sep 28 09:13:06 CEST 2015

On 25 September 2015 at 09:07, Alessio Bogon <youtux at gmail.com> wrote:
> I really like PEP 0505. The only thing that does not convince me is the `??` operator. I would like to know what you think of an alternative like `or?`:
> a_list = some_list or? []
> a_dict = some_dict or? {}
> The rationale behind is to let `or` do its job with “truthy” values, while `or?` would require non-None values.
> The rest of the PEP looks good to me.
> I apologise in advance if this was already proposed and I missed it.

It hasn't been suggested that I recall, and yes, I also prefer it to
the doubled ?? spelling. One concrete advantage is that it helps
convey that this is a short-circuiting control flow operator like
'and' and 'or' rather than a normal binary operator that always
evaluates both operands.


Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia

More information about the Python-ideas mailing list