From: Blaise Pabon Date: Fri, 23 May 2025 09:47:11 +0000 (-0400) Subject: gh-106318: Add example for `str.count()` (#134519) X-Git-Tag: v3.15.0a1~1552 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=17294680167d4b61dbf3d705f07b213b7c58e2dd;p=thirdparty%2FPython%2Fcpython.git gh-106318: Add example for `str.count()` (#134519) --- diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index ce6134768541..31d71031bca1 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -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")