views:

110

answers:

2

Sorry for the vague question. I would like to create a string that uses a plural if count > 1. For that, I would like have an "inline" condition that returns 's' to concatenate to my noun.

print "The plural of plural is plural{0}. {1}".format( {'s' if count > 1}, "Isnt't it!?")
+1  A: 
print "The plural of plural is plural{0}. {1}".format('s' if count > 1 else '', "Isnt't it!?")
Marcelo Cantos
Thanks to both of you!
booha
A: 

You need to add the else part to the 's' if count > 1 otherwise this is not a valid expression (because the value to return when count <= 1 has not been specified and Python cannot guess what this should be):

print "The plural of plural is plural{0}. {1}".format(
    's' if count > 1 else '', "Isnt't it!?")
Tendayi Mawushe
Thanks to both of you!
booha
Is there a way to do this in Python 2.4?
xitrium
to answer my own comment, it seems like {{{ count > 1 and 's' or '' }}} works.
xitrium