conditional expressions

Terry Reedy tjreedy at udel.edu
Thu Sep 19 06:12:43 CEST 2002


"daniel w. moore" <dan65536 at hotmail.com> wrote in message
news:33b491f.0209181820.17b6ea70 at posting.google.com...
> 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.

TJR





More information about the Python-list mailing list