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

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Sep 22 05:23:20 CEST 2005


Terry Reedy wrote:

> Many people, perhaps most, including me, read
> 
> exp1 if exp2 else exp3 # as
> cond if etrue else efalse # in direct analogy with
> cond ?  etrue :     efalse # from C

I'd have thought only Forth programmers would be prone to that!

It would surprise me greatly if it's really true that *most*
people would read it that way. Especially given that, in real
code, you're not going to be looking at abstract names like
exp1, exp2, exp3, but (hopefully) something a lot more
meaningful.

Can you honestly say that you would read

   return red_value if color == 'red' else blue_value

as

   if red_value:
     return color == 'red'
   else:
     return blue_value

?

-- 
Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg.ewing at canterbury.ac.nz	   +--------------------------------------+


More information about the Python-Dev mailing list