.format vs. %

Evan Driscoll edriscoll at wisc.edu
Sat Dec 31 13:47:02 EST 2011


How 'bout just:

>>> s = "{0} {1} {2} {3}"
>>> s.format(1, 2, 3, 4)
'1 2 3 4'

Evan


On 12/31/2011 13:44, davidfx wrote:
> Thanks for your response.  I know the following code is not going to be correct but I want to show you what I was thinking.
>
> formatter = "%r %r %r %r"
>
> print formatter % (1, 2, 3, 4)
>
> What is the .format version of this concept?
>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 552 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-list/attachments/20111231/3cf10c75/attachment-0001.sig>


More information about the Python-list mailing list