Is there some conditional operator in Python which would evaluate the first operand and return its value if it's not None
, or if it's None
, evaluate and return the second operand? I know that a or b
can almost do this, except that it does not strictly distinguish None
and False
. Looking for something similar to //
operator in Perl.
The goal is to write both a
and b
only once, therefore alternative a if a is not None else b
doesn't work either - both a
and b
can be expensive expressions.
a ?? b
), but it's suspended in limbo.None
. Which one is it?