Skip to content

Commit a63d03a

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 c6497d6 commit a63d03a

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

16651665
If *sub* is empty, returns the number of empty strings between characters
1666-
which is the length of the string plus one.
1667-
1666+
which is the length of the string plus one. For example::
1667+
1668+
>>> 'spam, spam, spam'.count('spam')
1669+
3
1670+
>>> 'spam, spam, spam'.count('spam', 5)
1671+
2
1672+
>>> 'spam, spam, spam'.count('spam', 5, 10)
1673+
1
1674+
>>> 'spam, spam, spam'.count('eggs')
1675+
0
1676+
>>> 'spam, spam, spam'.count('')
1677+
17
16681678

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

0 commit comments

Comments
 (0)