From 409a9a003dd9cdbb159d5f1afd3099b194fe1f74 Mon Sep 17 00:00:00 2001 From: blaisep Date: Thu, 22 May 2025 12:21:53 -0400 Subject: [PATCH 1/2] Add example for `str.endswith()` WIP to fix #106318 using the contributions from https://github.com/python/cpython/pull/105670 --- Doc/library/stdtypes.rst | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 3486a18b5cb1f0..a8bc0f7145be13 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1834,7 +1834,19 @@ expression support in the :mod:`re` module). 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. + 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 + + See also :meth:`startswith` and :meth:`removesuffix`. .. method:: str.expandtabs(tabsize=8) From 74ecd23322028be2dc4ba745a2fbf05243e19b46 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Date: Fri, 13 Jun 2025 14:47:52 +0300 Subject: [PATCH 2/2] Update Doc/library/stdtypes.rst --- Doc/library/stdtypes.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index a8bc0f7145be13..2309f4a6fba6ec 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -1834,7 +1834,7 @@ expression support in the :mod:`re` module). 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 + at that position. Using *start* and *end* is equivalent to ``str[start:end].endswith(suffix)``. For example:: >>> 'Python'.endswith('on')