Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
5508700
[Doc] Added snippet code to str.join method
adorilson May 11, 2021
e388d45
[Doc] Added snippet code to str.ljust method
adorilson May 12, 2021
d8407ba
[Doc] Added snippet code to str.rjust method
adorilson May 12, 2021
08b88ef
[Doc] Added 'See also' in str.lstrip and str.rstrip methods from one …
adorilson May 12, 2021
52e3a6b
[Doc] Added snippet code to str.maketrans method
adorilson May 12, 2021
dee059c
[Doc] Added snippet code to str.translate method
adorilson May 12, 2021
1671497
[Doc] Added snippet code to str.partition method
adorilson May 12, 2021
c832623
[Doc] Added snippet code to str.replace method
adorilson May 12, 2021
0be8170
[Doc] Added snippet code to str.rfind method
adorilson May 12, 2021
ff65bd2
[Doc] Added snippet code to str.rindex method
adorilson May 12, 2021
322c88c
[Doc] Added snippet code to str.rpartition method
adorilson May 12, 2021
3a473df
[DOC] minor change
adorilson May 12, 2021
b653693
[Doc] Added snippet code to str.rsplit method
adorilson May 12, 2021
1b412cb
[Doc] Added snippet code to str.startswith method
adorilson May 12, 2021
fb56441
[Doc] Added snippet code to str.swapcase method
adorilson May 12, 2021
04a5212
[Doc] Added snippet code to str.upper method
adorilson May 13, 2021
8771775
[DOC] Added snipped code in str.capitalize
adorilson Feb 27, 2021
f2e224c
[DOC] Add snippet code in str.casefold and str.lower methods
adorilson Feb 27, 2021
1d39f92
[DOC] Added snippet code in str.center method
adorilson Feb 27, 2021
b3a70b6
[DOC] Added snippet code in str.count method
adorilson Feb 27, 2021
37477f8
[DOC] fix typo
adorilson Feb 28, 2021
f9a7293
[DOC] Added snippet code in str.encode method
adorilson Mar 13, 2021
2e54cb0
[DOC] Added snippet code to str.endswith method
adorilson Mar 13, 2021
96d9bf6
[DOC] Added snippet code with \n to str.expandtabs method
adorilson Mar 13, 2021
d1dc7e0
[DOC] Added snippet code to str.index method
adorilson Mar 14, 2021
8661d8e
[DOC] Added snippet code to str.isalnum method
adorilson Mar 14, 2021
9e1f289
[DOC] Added snippet code in str.isalpha method
adorilson Mar 15, 2021
9e361d8
[DOC] Added snippet code in str.isascii method
adorilson Mar 15, 2021
09a463a
[DOC] Added snippet code to str.isdecimal method
adorilson Mar 15, 2021
641de5c
[Doc] Added snippet code to str.isdigit method
adorilson Mar 22, 2021
eae1564
[Doc] Added snippet code to str.islower method
adorilson Mar 22, 2021
58331b8
[Doc] Added snippet code to str.isnumeric method
adorilson Mar 22, 2021
d7ce39c
[Doc] Added snippet code to str.isprintable method
adorilson Mar 22, 2021
b86cefd
[Doc] Added snippet code to str.isspace method
adorilson Mar 22, 2021
3df630c
[Doc] Adde snippet code to str.istitle method
adorilson Mar 22, 2021
ae42fea
Minor changes (formatting and typo)
adorilson Jun 11, 2023
4676daa
[Doc] Making lint happy
adorilson Jun 11, 2023
7642f31
Merge branch 'main' into str_methods_2
adorilson Jul 3, 2023
de11c93
Update Doc/library/stdtypes.rst
adorilson Jul 3, 2023
1695b93
[DOC] Added some 'see also' to str methods
adorilson Jul 3, 2023
ad6b56b
[DOC] Moved 'For example' to the end of the previous paragraph
adorilson Jul 3, 2023
e4e1405
[DOC] Putting a space after # in comments on str methods
adorilson Jul 3, 2023
2dfa3f2
[DOC] Fixed inconsistent literal block quoting
adorilson Jul 3, 2023
f39fa74
[DOC] Make str methods collapsible - part 1
adorilson Nov 4, 2023
adc4ee5
Merge branch 'main' into str_methods_collapsible
adorilson Jan 14, 2024
7e5c86d
Doc: minor fix
adorilson Jan 14, 2024
5cf0f50
[DOC] Removing some trailing whitespace (stdtypes)
adorilson Jan 14, 2024
7f6a528
[DOC] Make str methods example collapsible - pt 2
adorilson Jan 14, 2024
1543a9a
Doc: Make str methods example collapsible - pt 3
adorilson Jan 20, 2024
189a24b
Doc: Apply suggestions from code review to Doc/library/stdtypes.rst
adorilson Jan 23, 2024
47ba07f
Doc: Make str methods example collapsible - pt 4
adorilson Jan 27, 2024
8e982bf
Doc: Make str methods example collapsible - pt 5
adorilson Jan 29, 2024
9abd8fe
Merge branch 'main' into str_methods_collapsible
adorilson Feb 11, 2024
bd831e2
Doc: Make str methods example collapsible - pt 6
adorilson Feb 11, 2024
b1169f4
Doc: Make str methods example collapsible - pt 7
adorilson Feb 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Doc: Make str methods example collapsible - pt 7
  • Loading branch information
adorilson committed Feb 11, 2024
commit b1169f41f19b69e83fdbd990c638cb289b79253f
195 changes: 141 additions & 54 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2509,29 +2509,51 @@ True

If the string starts with the *prefix* string, return
``string[len(prefix):]``. Otherwise, return a copy of the original
string. For example::

>>> 'TestHook'.removeprefix('Test')
'Hook'
>>> 'BaseTestCase'.removeprefix('Test')
'BaseTestCase'
string.

.. versionadded:: 3.9

.. raw:: html

<dd>
<details>
<summary><a style="cursor:pointer;">See example</a></summary>

>>> 'TestHook'.removeprefix('Test')
'Hook'
>>> 'BaseTestCase'.removeprefix('Test')
'BaseTestCase'

.. raw:: html

</details>
</dd>


.. method:: str.removesuffix(suffix, /)

If the string ends with the *suffix* string and that *suffix* is not empty,
return ``string[:-len(suffix)]``. Otherwise, return a copy of the
original string. For example::

>>> 'MiscTests'.removesuffix('Tests')
'Misc'
>>> 'TmpDirMixin'.removesuffix('Tests')
'TmpDirMixin'
original string.

.. versionadded:: 3.9

.. raw:: html

<dd>
<details>
<summary><a style="cursor:pointer;">See example</a></summary>

>>> 'MiscTests'.removesuffix('Tests')
'Misc'
>>> 'TmpDirMixin'.removesuffix('Tests')
'TmpDirMixin'

.. raw:: html

</details>
</dd>


.. method:: str.replace(old, new, count=-1)

Expand All @@ -2542,80 +2564,142 @@ True
.. versionchanged:: 3.13
*count* is now supported as a keyword argument.

For example::
.. raw:: html

>>> 'spam, spam, spam'.replace('spam', 'eggs')
'eggs, eggs, eggs'
>>> 'spam, spam, spam'.replace('spam', 'eggs', 1)
'eggs, spam, spam'
<dd>
<details>
<summary><a style="cursor:pointer;">See example</a></summary>

>>> 'spam, spam, spam'.replace('spam', 'eggs')
'eggs, eggs, eggs'
>>> 'spam, spam, spam'.replace('spam', 'eggs', 1)
'eggs, spam, spam'

.. raw:: html

</details>
</dd>


.. method:: str.rfind(sub[, start[, end]])

Return the highest index in the string where substring *sub* is found, such
that *sub* is contained within ``s[start:end]``. Optional arguments *start*
and *end* are interpreted as in slice notation. Return ``-1`` on failure.
For example::

>>> 'spam, spam, spam'.rfind('sp')
12
>>> 'spam, spam, spam'.rfind('sp', 0, 10)
6

See also :meth:`find`.

.. raw:: html

<dd>
<details>
<summary><a style="cursor:pointer;">See example</a></summary>

>>> 'spam, spam, spam'.rfind('sp')
12
>>> 'spam, spam, spam'.rfind('sp', 0, 10)
6

.. raw:: html

</details>
</dd>


.. method:: str.rindex(sub[, start[, end]])

Like :meth:`rfind` but raises :exc:`ValueError` when the substring *sub* is not
found. For example::

>>> 'spam, spam, spam'.rindex('eggs')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: substring not found
found.

See also :meth:`index`.

.. raw:: html

<dd>
<details>
<summary><a style="cursor:pointer;">See example</a></summary>

>>> 'spam, spam, spam'.rindex('eggs')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: substring not found

.. raw:: html

</details>
</dd>


.. method:: str.rjust(width[, fillchar])

Return the string right justified in a string of length *width*. Padding is
done using the specified *fillchar* (default is an ASCII space). The
original string is returned if *width* is less than or equal to ``len(s)``.
For example::

>>> 'Python'.rjust(10)
' Python'
>>> 'Python'.rjust(10, '.')
'....Python'

See also :meth:`ljust`.

.. raw:: html

<dd>
<details>
<summary><a style="cursor:pointer;">See example</a></summary>

>>> 'Python'.rjust(10)
' Python'
>>> 'Python'.rjust(10, '.')
'....Python'

.. raw:: html

</details>
</dd>


.. method:: str.rpartition(sep)

Split the string at the last occurrence of *sep*, and return a 3-tuple
containing the part before the separator, the separator itself, and the part
after the separator. If the separator is not found, return a 3-tuple containing
two empty strings, followed by the string itself. For example::

>>> "Monty Python's Flying Circus".rpartition(' ')
("Monty Python's Flying", ' ', 'Circus')
two empty strings, followed by the string itself.

See also :meth:`partition`.

.. raw:: html

<dd>
<details>
<summary><a style="cursor:pointer;">See example</a></summary>

>>> "Monty Python's Flying Circus".rpartition(' ')
("Monty Python's Flying", ' ', 'Circus')

.. raw:: html

</details>
</dd>


.. method:: str.rsplit(sep=None, maxsplit=-1)

Return a list of the words in the string, using *sep* as the delimiter string.
If *maxsplit* is given, at most *maxsplit* splits are done, the *rightmost*
ones. If *sep* is not specified or ``None``, any whitespace string is a
separator. Except for splitting from the right, :meth:`rsplit` behaves like
:meth:`split` which is described in detail below. For example::
:meth:`split` which is described in detail below.

>>> '1,2,3'.rsplit(',', maxsplit=1)
['1,2', '3']
.. raw:: html

<dd>
<details>
<summary><a style="cursor:pointer;">See example</a></summary>

>>> '1,2,3'.rsplit(',', maxsplit=1)
['1,2', '3']

.. raw:: html

</details>
</dd>


.. method:: str.rstrip([chars])
Expand All @@ -2624,22 +2708,25 @@ True
argument is a string specifying the set of characters to be removed. If omitted
or ``None``, the *chars* argument defaults to removing whitespace. The *chars*
argument is not a suffix; rather, all combinations of its values are stripped.
For example::

>>> ' spacious '.rstrip()
' spacious'
>>> 'mississippi'.rstrip('ipz')
'mississ'
See also :meth:`lstrip` and see :meth:`str.removesuffix` for a method that will
remove a single suffix string rather than all of a set of characters.

.. raw:: html

<dd>
<details>
<summary><a style="cursor:pointer;">See example</a></summary>

See :meth:`str.removesuffix` for a method that will remove a single suffix
string rather than all of a set of characters. For example::
>>> ' spacious '.rstrip()
' spacious'
>>> 'mississippi'.rstrip('ipz')
'mississ'

>>> 'Monty Python'.rstrip(' Python')
'M'
>>> 'Monty Python'.removesuffix(' Python')
'Monty'
.. raw:: html

See also :meth:`lstrip`.
</details>
</dd>


.. method:: str.split(sep=None, maxsplit=-1)
Expand Down