PEP 308 - keeping it simple

djw dwelch91 at no.spam.attbi.com
Sun Feb 16 10:56:33 EST 2003


Ian Parker wrote:
> Several posters have mentioned the FAQ entry:
> 
> 4.16. Is there an equivalent of C's "?:" ternary operator?
> 
> Different implementations of a ternary operator will lead to
> embarrassing FAQ entries:
> 
> 4.16. Is there an equivalent of C's "?:" ternary operator?
> Yes, as you know Python is an elegantly simple language and of course
> provides a ternary operator equivalent to "c?a:b", although more
> long-winded, and requiring parentheses
> 
>   (if c then a else b)
> 
> or
> 
> 4.16. Is there an equivalent of C's "?:" ternary operator?
> Yes, just use a similar construction to an if statement, but swap the
> order of the terms around a little to get
>     a if c else b
> which everyone agrees would be a natural way to express a conditional,
> if one wasn't already familiar with the order used in if statements.
> 
> 
> Let's just go for the C way of doing this so that we can drop the FAQ
> entry entirely.
> 
Or, we could just adopt C syntax for the entire language and drop Python 
specific documentation altogether. <Wink> Seriously though, for me, 
having syntax that looks like C (or Perl, Pascal, etc, etc) is not 
something to strive for. On the contrary, I find constructs like x ? y : 
z to be rather hard to read. Python is not C. Let's keep it that way!

/d/





More information about the Python-list mailing list