Does python support the expression "a = b | 1"???

François Pinard pinard at iro.umontreal.ca
Wed Oct 5 11:25:26 EDT 2005


[Wenhua Zhao]
> a = b | 1

> a = b if b != nil
> else a =1

> Is there such expression in python?

Hi.  Merely write:

   a = b or 1

In Python, there is no `nil'. `a' will receive 1 instead of the value of
`b' only if `b' is either zero, None, False, or empty in some way.

-- 
François Pinard   http://pinard.progiciels-bpi.ca



More information about the Python-list mailing list