print... okay, howabout sprintf?
Manus Hand
mjhand at concentric.net
Sun May 7 03:50:50 EDT 2000
Courageous wrote:
>
> Okay, I've noticed that python print supports printf style format
> notation, and that's cool. But how do you do the same thing with
> strings. i.e., what's the equivalent of sprintf()?
>
>
You found your answer in the % operator. Just use it in an
assignment statement instead of in a print statement:
>>> result = "%d + %d = %d...Isn't that %s?" % (2, 2, 2+2, 'cool')
>>> print result
2 + 2 = 4...Isn't that cool?
>>>
Manus
More information about the Python-list
mailing list