Skip to content

Commit 1dbb644

Browse files
[3.13] gh-106318: Add example for str.count() (GH-134519) (#134573)
Co-authored-by: Blaise Pabon <[email protected]>
1 parent 5b203f5 commit 1dbb644

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

16711671
If *sub* is empty, returns the number of empty strings between characters
1672-
which is the length of the string plus one.
1673-
1672+
which is the length of the string plus one. For example::
1673+
1674+
>>> 'spam, spam, spam'.count('spam')
1675+
3
1676+
>>> 'spam, spam, spam'.count('spam', 5)
1677+
2
1678+
>>> 'spam, spam, spam'.count('spam', 5, 10)
1679+
1
1680+
>>> 'spam, spam, spam'.count('eggs')
1681+
0
1682+
>>> 'spam, spam, spam'.count('')
1683+
17
16741684

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

0 commit comments

Comments
 (0)