]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-106318: Add example for `str.endswith()` (GH-134523) (#135459)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 13 Jun 2025 12:14:21 +0000 (14:14 +0200)
committerGitHub <noreply@github.com>
Fri, 13 Jun 2025 12:14:21 +0000 (15:14 +0300)
gh-106318: Add example for `str.endswith()` (GH-134523)
(cherry picked from commit eed827ed091c6e55f11164046d287a76e30fbc0e)

Co-authored-by: Blaise Pabon <blaise@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Doc/library/stdtypes.rst

index 4854a2c077bb2833b93f9f4ce9af92f20cbc5016..0954e3409a2dcc70e38fed374d52b9efc9762cee 100644 (file)
@@ -1863,7 +1863,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. Using *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)