conditional expressions (RE: Loop-and-a-half (Re: Curious assignment behaviour))

Paul Rubin phr-n2001d at nightsong.com
Tue Oct 16 04:31:11 EDT 2001


"Anders J. Munch" <andersjm at dancontrol.dk> writes:
> Combine that with the form mentioned (though not preferred) by Michael
> Abbott elsewhere we get:
> 
>     x = (if e1: e2 else: e3)
> 
> No new keyword, consistent with if-statement syntax and hence more
> intuitive to someone who knows Python but not a heap of other
> languages as well.  And it's slightly more terse than the if-then-else
> form, which is important because terseness is the only reason to use a
> conditional expression in the first place.

Hey, I like that one too.  You could even include an elif:
  x = (if e1: v1 elif e2: v2 else: v3)



More information about the Python-list mailing list