conditional expressions

Terry Reedy tjreedy at
Thu Sep 19 00:12:43 EDT 2002

"daniel w. moore" <dan65536 at> wrote in message
news:33b491f.0209181820.17b6ea70 at
> It's occurred to me after some brainstorming on the subject that the
> C/perl construct
>   a ? b : c
> can be arranged like this in python:
>   (a and [b] or [c])[0]

If you *know* that b will evaluate as True (perhaps because it is a
non-null constant, then this can be simplified to 'a and b or c'.  I
first used this several years ago.


More information about the Python-list mailing list