Skip to content

Commit eed827e

Browse files
blaisephugovk
andauthored
gh-106318: Add example for str.endswith() (#134523)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
1 parent 2734595 commit eed827e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

Doc/library/stdtypes.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,19 @@ expression support in the :mod:`re` module).
18631863
Return ``True`` if the string ends with the specified *suffix*, otherwise return
18641864
``False``. *suffix* can also be a tuple of suffixes to look for. With optional
18651865
*start*, test beginning at that position. With optional *end*, stop comparing
1866-
at that position.
1866+
at that position. Using *start* and *end* is equivalent to
1867+
``str[start:end].endswith(suffix)``. For example::
1868+
1869+
>>> 'Python'.endswith('on')
1870+
True
1871+
>>> 'a tuple of suffixes'.endswith(('at', 'in'))
1872+
False
1873+
>>> 'a tuple of suffixes'.endswith(('at', 'es'))
1874+
True
1875+
>>> 'Python is amazing'.endswith('is', 0, 9)
1876+
True
1877+
1878+
See also :meth:`startswith` and :meth:`removesuffix`.
18671879

18681880

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

0 commit comments

Comments
 (0)