Skip to content

Commit 1729468

Browse files
authored
gh-106318: Add example for str.count() (#134519)
1 parent da9b5c1 commit 1729468

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)