Conditional operator in Python?

Ignacio Vazquez-Abrams ignacio at openservices.net
Thu Sep 6 15:05:35 EDT 2001


On 6 Sep 2001, Marcin 'Qrczak' Kowalczyk wrote:

> What about:
>
>     if X: Y else: Z
>
> There is no conceptual conflict with the statement if, because when
> a statement can be understood in both ways, they have the same effect
> anyway. I'm only not sure if it's easy to parse using current Python
> parser.

This sounds good to me because all that would have to happen is that the
statement would have to return the value of the "true" statement, which in
normal usage would be None anyways.

Plus, it can lead into things like:

  v=if a: x elif b: y else: z

which is probably a lot cleaner than:

  v=((a)?(x):((b)?(y):(z)))

-- 
Ignacio Vazquez-Abrams  <ignacio at openservices.net>





More information about the Python-list mailing list