Wenhua Zhao wrote:
> a = b | 1
>
> a = b if b != nil
> else a =1
>
> Is there such expression in python?
Soon there will be, but currently: no. What you are after is a ternary
operator like _?_:_ in C. There have been plenty of discussions about
these - search this NG. Depending on your usecase, either
if b is not None:
a = b
else:
a = 1
or
a = [1,b][b is not None]
or even
a = b or 1
will do the trick.
But PLEASE read the discussions first, to understand the reasons and
implications.
Diez
--
http://mail.python.org/mailman/listinfo/python-list