Anybody working on a PEP308 summary?
ark at research.att.com
Sun Feb 9 16:11:49 CET 2003
Giles> Technique number 2:
Giles> if condition:
Giles> x = expr1
Giles> x = expr2
Giles> Which is three extra lines and suffers from the possibility of
Giles> introducing a bug through mis-typing x.
I would like to strengthen this statement slightly. Instead of
x = condition and expr1 or expr2
let's look at
print "The value is", x[i>0 and i else 0]
Here I have carefully chosen the value in the  to avoid the
bug mentioned in Technique 1. Now the alternatives are
print "The value is", x[i]
print "The value is", x
which repeats much more than just "x ="
print "The value is",
which some people will find obscure because of the print with the
trailing comma, or
if i > 0:
val = x[i]
val = x
print "The value is", val
which introduces an extra variable.
Andrew Koenig, ark at research.att.com, http://www.research.att.com/info/ark
More information about the Python-list