.format vs. %

Benjamin Kaplan benjamin.kaplan at case.edu
Sat Dec 31 13:57:13 EST 2011


On Dec 31, 2011 1:46 PM, "davidfx" <dgeorge29ca at gmail.com> 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?
>

format is a method of the string class. You store the string the same way
you would any other.

formatter = "Hello, {}"
print(formatter.format("world"))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20111231/f791ab58/attachment-0001.html>


More information about the Python-list mailing list