compound statement from C "<test>?<true-val>:<false-val>"

Jussi Salmela tiedon_jano at hotmail.com
Fri Feb 2 10:14:14 EST 2007


Holger kirjoitti:
>
> I would like to do the equivalent if python of the C line:
> printf("I saw %d car%s\n", n, n != 1 ? "s" : "")
> 
> Please help
> 
> /Holger
> 

In this particular case you don't need the ternary operator:

	print "I saw %d car%s\n" % (n, ("", "s")[n != 1])


Cheers,
Jussi



More information about the Python-list mailing list