compound statement from C "<test>?<true-val>:<false-val>"
BJörn Lindqvist
bjourne at gmail.com
Sun Feb 11 20:42:56 EST 2007
On 11 Feb 2007 16:57:07 -0800, Carl Banks <pavlovevidence at gmail.com> wrote:
> You don't need any ternary operator to avoid repetition, anyways. You
> could factor the common parts out like this:
>
> if n == 1:
> what = "a car"
> else:
> what = "%d cars" % n
> print "I saw %s" % what
Or even better (IMHO):
what = "%d cars" % n
if n == 1:
what = "a car"
print "I saw %s" % what
One less line and just as readable.
> but what's the point? It's just a few repeated characters two lines
> apart. Peter's version is the most easily read version here,
> including the one using the official ternary operator.
Agreed.
--
mvh Björn
More information about the Python-list
mailing list