[Python-ideas] Null coalescing operator

MRAB python at mrabarnett.plus.com
Thu Nov 3 15:00:03 EDT 2016


On 2016-11-03 18:36, Chris Barker wrote:
> Thanks Steven, this is great!
>
> so -- when all this started, I think one of the use cases was to clean
> up this really common idiom:
>
> self.an_arg = the_default if an_arg is None else an_arg
>
> so would that be:
>
> self.an_arg = the_default ?? an_arg
>
> That would be nice.
>
> Though the fact that I'm still not sure if that's correct makes me think
> this is not so intuitive!
>
No, ?? is a bit like 'or', except that only None is falsey, so it would be:

     self.an_arg = an_arg ?? the_default



More information about the Python-ideas mailing list