conditional expressions

thp at thp at
Sun Sep 22 22:13:55 EDT 2002

Terry Reedy <tjreedy at> wrote:

+ "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.

But why use grotesque hacks in the first place?  "a ? b : c" is a
well-established syntax for conditional expressions.  Why doesn't
Python simply adopt it?

Tom Payne

More information about the Python-list mailing list