compound statement from C "<test>?<true-val>:<false-val>"
Jussi Salmela
tiedon_jano at hotmail.com
Fri Feb 2 10:14:14 EST 2007
More information about the Python-list mailing list
Fri Feb 2 10:14:14 EST 2007
- Previous message (by thread): compound statement from C "<test>?<true-val>:<false-val>"
- Next message (by thread): compound statement from C "<test>?<true-val>:<false-val>"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message (by thread): compound statement from C "<test>?<true-val>:<false-val>"
- Next message (by thread): compound statement from C "<test>?<true-val>:<false-val>"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list