diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 4f7d794de403a5..089cdd428d3062 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1852,13 +1852,7 @@ True Return the lowest index in the string where substring *sub* is found within the slice ``s[start:end]``. Optional arguments *start* and *end* are - interpreted as in slice notation. Return ``-1`` if *sub* is not found. For - example:: - - >>> 'spam, spam, spam'.find('sp') - 0 - >>> 'spam, spam, spam'.find('sp', 5) - 6 + interpreted as in slice notation. Return ``-1`` if *sub* is not found. See also :meth:`rfind` and :meth:`index`. @@ -1871,6 +1865,22 @@ True >>> 'Py' in 'Python' True +.. raw:: html + +
+
+ See example + +>>> 'spam, spam, spam'.find('sp') +0 +>>> 'spam, spam, spam'.find('sp', 5) +6 + +.. raw:: html + +
+
+ .. method:: str.format(*args, **kwargs) @@ -1879,10 +1889,7 @@ True ``{}``. Each replacement field contains either the numeric index of a positional argument, or the name of a keyword argument. Returns a copy of the string where each replacement field is replaced with the string value of - the corresponding argument. For example:: - - >>> "The sum of 1 + 2 is {0}".format(1+2) - 'The sum of 1 + 2 is 3' + the corresponding argument. See :ref:`formatstrings` for a description of the various formatting options that can be specified in format strings. @@ -1902,22 +1909,47 @@ True temporarily the ``LC_CTYPE`` locale to the ``LC_NUMERIC`` locale in some cases. +.. raw:: html + +
+
+ See example + +>>> "The sum of 1 + 2 is {0}".format(1+2) +'The sum of 1 + 2 is 3' + +.. raw:: html + +
+
+ .. method:: str.format_map(mapping) 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. For example:: - - >>> class Default(dict): - ... def __missing__(self, key): - ... return key - ... - >>> '{name} was born in {country}'.format_map(Default(name='Guido')) - 'Guido was born in country' + if for example ``mapping`` is a dict subclass. .. versionadded:: 3.2 +.. raw:: html + +
+
+ See example + +>>> class Default(dict): +... def __missing__(self, key): +... return key +... +>>> '{name} was born in {country}'.format_map(Default(name='Guido')) +'Guido was born in country' + +.. raw:: html + +
+
+ .. method:: str.index(sub[, start[, end]])