From: Eric Smith Date: Sat, 6 Nov 2010 13:22:13 +0000 (+0000) Subject: Added example for str.format_map(). X-Git-Tag: v3.2a4~100 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5ad85f81b0664fafcd936b1dbfb728a3ace8f7a2;p=thirdparty%2FPython%2Fcpython.git Added example for str.format_map(). --- diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index ebe7b7604c85..0ac870be2175 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -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]])