]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106318: Add example for `str.count()` (#134519)
authorBlaise Pabon <blaise@gmail.com>
Fri, 23 May 2025 09:47:11 +0000 (05:47 -0400)
committerGitHub <noreply@github.com>
Fri, 23 May 2025 09:47:11 +0000 (12:47 +0300)
Doc/library/stdtypes.rst

index ce613476854110f52b67b82ed74ff4c3b6584be7..31d71031bca12c8157e3c2bf098ff3db36a5c807 100644 (file)
@@ -1805,8 +1805,18 @@ expression support in the :mod:`re` module).
    interpreted as in slice notation.
 
    If *sub* is empty, returns the number of empty strings between characters
-   which is the length of the string plus one.
-
+   which is the length of the string plus one. For example::
+
+      >>> 'spam, spam, spam'.count('spam')
+      3
+      >>> 'spam, spam, spam'.count('spam', 5)
+      2
+      >>> 'spam, spam, spam'.count('spam', 5, 10)
+      1
+      >>> 'spam, spam, spam'.count('eggs')
+      0
+      >>> 'spam, spam, spam'.count('')
+      17
 
 .. method:: str.encode(encoding="utf-8", errors="strict")