Skip to content

Commit

Permalink
[DOC] Make str methods example collapsible - pt 2
Browse files Browse the repository at this point in the history
  • Loading branch information
adorilson committed Jan 14, 2024
1 parent 5cf0f50 commit 7f6a528
Showing 1 changed file with 60 additions and 28 deletions.
88 changes: 60 additions & 28 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1754,15 +1754,8 @@ expression support in the :mod:`re` module).
See :ref:`error-handlers` for details.

For performance reasons, the value of *errors* is not checked for validity
unless an encoding error actually occurs,
:ref:`devmode` is enabled
or a :ref:`debug build <debug-build>` is used. For example::

>>> encoded_str_to_byte = 'Python'.encode()
>>> type(encoded_str_to_byte)
<class 'bytes'>
>>> encoded_str_to_byte
b'Python'
unless an encoding error actually occurs, :ref:`devmode` is enabled or a
:ref:`debug build <debug-build>` is used.

.. versionchanged:: 3.1
Added support for keyword arguments.
Expand All @@ -1771,26 +1764,54 @@ expression support in the :mod:`re` module).
The value of the *errors* argument is now checked in :ref:`devmode` and
in :ref:`debug mode <debug-build>`.

.. raw:: html

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

>>> encoded_str_to_byte = 'Python'.encode()
>>> type(encoded_str_to_byte)
<class 'bytes'>
>>> encoded_str_to_byte
b'Python'

.. raw:: html

</details>
</dd>


.. method:: str.endswith(suffix[, start[, end]])

Return ``True`` if the string ends with the specified *suffix*, otherwise return
``False``. *suffix* can also be a tuple of suffixes to look for. With optional
*start*, test beginning at that position. With optional *end*, stop comparing
at that position. Use the *start* and *end* is equivalent to
``str[start:end].endswith(suffix)``. For example::

>>> 'Python'.endswith('on')
True
>>> 'a tuple of suffixes'.endswith(('at', 'in'))
False
>>> 'a tuple of suffixes'.endswith(('at', 'es'))
True
>>> 'Python is amazing'.endswith('is', 0, 9)
True
``str[start:end].endswith(suffix)``.

See also :meth:`startswith` and :meth:`removesuffix`.

.. raw:: html

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

>>> 'Python'.endswith('on')
True
>>> 'a tuple of suffixes'.endswith(('at', 'in'))
False
>>> 'a tuple of suffixes'.endswith(('at', 'es'))
True
>>> 'Python is amazing'.endswith('is', 0, 9)
True

.. raw:: html

</details>
</dd>


.. method:: str.expandtabs(tabsize=8)

Expand All @@ -1805,15 +1826,26 @@ expression support in the :mod:`re` module).
(``\n``) or return (``\r``), it is copied and the current column is reset to
zero. Any other character is copied unchanged and the current column is
incremented by one regardless of how the character is represented when
printed. For example::

>>> '01\t012\t0123\t01234'.expandtabs()
'01 012 0123 01234'
>>> '01\t012\t0123\t01234'.expandtabs(4)
'01 012 0123 01234'
>>> print('01\t012\n0123\t01234'.expandtabs(4))
01 012
0123 01234
printed.

.. raw:: html

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

>>> '01\t012\t0123\t01234'.expandtabs()
'01 012 0123 01234'
>>> '01\t012\t0123\t01234'.expandtabs(4)
'01 012 0123 01234'
>>> print('01\t012\n0123\t01234'.expandtabs(4))
01 012
0123 01234

.. raw:: html

</details>
</dd>


.. method:: str.find(sub[, start[, end]])
Expand Down

0 comments on commit 7f6a528

Please sign in to comment.