]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-106318: Add example for `str.count()` (GH-134519) (#134573)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 23 May 2025 09:53:19 +0000 (11:53 +0200)
committerGitHub <noreply@github.com>
Fri, 23 May 2025 09:53:19 +0000 (09:53 +0000)
Co-authored-by: Blaise Pabon <blaise@gmail.com>
Doc/library/stdtypes.rst

index a856047f2d6e8262e70ea8519c8dd32c4bb3dae0..2c1ca4627795f3b328ecab1654373ec07829080c 100644 (file)
@@ -1669,8 +1669,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")