[Python-Dev] Adding a conditional expression in Py3.0

Thomas Lotze tl at gocept.com
Wed Sep 21 00:32:53 CEST 2005


Guido van Rossum wrote:

> I think I'd prefer (if <expr> then <expr> else <expre>) i.e. no colons.
> None of the other  expression forms (list comprehensions and generator
> expressions) involving statement keywords use colons.

While I like the looks of the form without colons better, I can't quite
follow this argument for it.

In LCs and GEs, colons wouldn't make any sense in the first place because
the expression controlled by "for" and "if" is written before it:
[expression(x) for x in y]. Just where would anyone put a colon there,
anyway?

A colon does make sense if something follows it, as is currently the case
in lambda expressions. It would also be the case in an (if x: y else: z)
form.

I have a feeling that trying to make all expression forms which happen to
use statement keywords colon-free is seeking an artificial consistency.
I'm happy to be proven wrong, though.

+1 on the idea of introducing a conditional expression in the first place,
though.

-- 
Thomas




More information about the Python-Dev mailing list