Skip to content

Commit b5fa558

Browse files
blaisepmiss-islington
authored andcommitted
pythongh-106318: Add example for str.count() (pythonGH-134519)
(cherry picked from commit 1729468) Co-authored-by: Blaise Pabon <[email protected]>
1 parent 73967c4 commit b5fa558

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

Doc/library/stdtypes.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,8 +1799,18 @@ expression support in the :mod:`re` module).
17991799
interpreted as in slice notation.
18001800

18011801
If *sub* is empty, returns the number of empty strings between characters
1802-
which is the length of the string plus one.
1803-
1802+
which is the length of the string plus one. For example::
1803+
1804+
>>> 'spam, spam, spam'.count('spam')
1805+
3
1806+
>>> 'spam, spam, spam'.count('spam', 5)
1807+
2
1808+
>>> 'spam, spam, spam'.count('spam', 5, 10)
1809+
1
1810+
>>> 'spam, spam, spam'.count('eggs')
1811+
0
1812+
>>> 'spam, spam, spam'.count('')
1813+
17
18041814

18051815
.. method:: str.encode(encoding="utf-8", errors="strict")
18061816

0 commit comments

Comments
 (0)