En Sun, 11 Feb 2007 19:16:49 -0300, Holger <[EMAIL PROTECTED]> escribió:

>> >> if n == 1:
>> >>     print "I saw a car"
>> >> else:
>> >>     print "I saw %d cars" % n
>
> Personally I don't like the if-else approach because of the don't-
> repeat-yourself philosophy
>
>> D'accord. Did I mention that, as a "for fun" approach, "s" * (n != 1) is
>> quite clever :-)
> I like this one :-)
>
>> print "I saw %d car%s\n" % (n, ("", "s")[n != 1])
> And this one.

I presume all of this is only used as an example on using expressions. In  
any application with any chances of being i18n, the only viable way is the  
first one. Doing algebra on phrases is a no-no.

-- 
Gabriel Genellina

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to