On Sep 25, 3:16 am, Pete Forman <[EMAIL PROTECTED]> wrote:
> Asun Friere <[EMAIL PROTECTED]> writes:
>
>  > A canonical use of the conditional operator is in
>  > pluralising words, (eg. '%s dollar' % n + 's' if n!=1 else '').
>
> That fails for n == 1.  So what is best?
>

Sorry missing parantheses.  I should test, even for fragments written
out as part of a sentence. %-/

> for i in range(4):
>     print '%d thing' % i + ('s' if i != 1 else '')
>

That's the corrected version of what I meant, but actually I think
your last version ('%d thing%s' % (i, 's' if i != 1 else '')), holding
all variables for placeholders in the tuple, is better. It's certainly
more readible.
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to