[Tutor] String formatting question with 's'.format()
Evgeny Izetov
eizetov at gmail.com
Wed Jun 8 23:48:25 CEST 2011
I see now, that example helps. Basically I use one asterisk to extract a
list or a tuple and double asterisks for a dictionary, but I have to provide
keys in case of a dictionary, like here:
>>> template = '{motto}, {pork} and {food}'
>>> a = dict(motto='spam', pork='ham', food='eggs')
>>> template.format(**a)
'spam, ham and eggs'
Thanks for clearing things up.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110608/9b7b8007/attachment.html>
More information about the Tutor
mailing list