[Python-ideas] Using "||" (doubled pipe) as the null coalescing operator?
Nick Coghlan
ncoghlan at gmail.com
Thu Sep 24 05:00:39 CEST 2015
On 24 Sep 2015 01:59, "Nick Coghlan" <ncoghlan at gmail.com> wrote:
>
> The only other potential spelling of the coalescence case that comes
> to mind is to make "?" available in conditional expressions as a
> reference to the LHS:
>
> data = data if ? is not None else []
> headers = headers if ? is not None else {}
> title = user_title if ? is not None else local_default_title if ?
> is not None else global_default_title
One advantage of this more explicit spelling is that it permits sentinels
other than None in the expanded form:
data = data if ? is not sentinel else default()
Only the shorthand cases (augmented assignment, attribute access, subscript
lookup) would be restricted to checking specifically against None.
Cheers,
Nick.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150924/8430e355/attachment.html>
More information about the Python-ideas
mailing list