Skip to content

Commit 896b745

Browse files
[3.14] gh-106318: Add example for str.count() (GH-134519) (#134574)
Co-authored-by: Blaise Pabon <[email protected]>
1 parent 7efe67a commit 896b745

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
@@ -1805,8 +1805,18 @@ expression support in the :mod:`re` module).
18051805
interpreted as in slice notation.
18061806

18071807
If *sub* is empty, returns the number of empty strings between characters
1808-
which is the length of the string plus one.
1809-
1808+
which is the length of the string plus one. For example::
1809+
1810+
>>> 'spam, spam, spam'.count('spam')
1811+
3
1812+
>>> 'spam, spam, spam'.count('spam', 5)
1813+
2
1814+
>>> 'spam, spam, spam'.count('spam', 5, 10)
1815+
1
1816+
>>> 'spam, spam, spam'.count('eggs')
1817+
0
1818+
>>> 'spam, spam, spam'.count('')
1819+
17
18101820

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

0 commit comments

Comments
 (0)