Added example for str.format_map().

This commit is contained in:
Eric Smith 2010-11-06 13:22:13 +00:00
parent 7322fcf84b
commit 5ad85f81b0
1 changed files with 10 additions and 2 deletions

View File

@ -1042,9 +1042,17 @@ functions based on regular expressions.
Similar to ``str.format(**mapping)``, except that ``mapping`` is
used directly and not copied to a :class:`dict` . This is useful
if for example ``mapping`` is a dict subclass.
if for example ``mapping`` is a dict subclass:
>>> class Default(dict):
... def __missing__(self, key):
... return key
...
>>> '{name} was born in {country}'.format_map(Default(name='Guido'))
'Guido was born in country'
.. versionadded:: 3.2
.. versionadded:: 3.2
.. method:: str.index(sub[, start[, end]])