trinary operator - if then else

Michael Bentley michael at jedimindworks.com
Wed Apr 25 07:02:53 EDT 2007


On Apr 25, 2007, at 1:58 AM, Alchemist wrote:

> What is Python's version for the trinary if..then..else operator?
>
> I want a one-liner such as
>   a?b:c
> for the if..then..else control structure
> if a
>   then b
>   else c
>
> Does Python 2.4 support it?

Not precisely, but you can *usually* get away with:

a and b or c






More information about the Python-list mailing list