Python String Count() MethodLast Updated : 29 Dec 2025 It returns the number of occurences of substring in the specified range. It takes three parameters, first is a substring, second a start index and third is last index of the range. Start and end both are optional whereas substring is required. Python String count() Method SyntaxIt has the following syntax: Parameters
Return TypeIt returns number of occurrences of substring in the range. Different Examples for Python String count() MethodLet's see some examples to understand the count() method. Python String count() Method Example 1Let us take an example to demonstrate the working of the string count() method in Python. Output: occurences: 2 Python String Count() Method Example 2Let us take an example to demonstrate the working of the string count() method in Python. Here, we are passing second parameter (start index). Python String Count() Method Example 3Let us take another example to demonstrate the working of the string count() method in Python. Output: occurences: 5 Python String Count() Method Example 4The given example is using all three parameters and returning result from the specified range. Output: occurences: 1 Python String Count() Method Example 5It can count non-alphabet chars also, see the given example. Output: occurences: 3 Next TopicPython Strings |
We request you to subscribe our newsletter for upcoming updates.