Python String Count() MethodIt 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. SignatureParameters
Return TypeIt returns number of occurrences of substring in the range. Let's see some examples to understand the count() method. Python String Count() Method Example 1Output: occurences: 2 Python String Count() Method Example 2Here, we are passing second parameter (start index). Python String Count() Method Example 3Output: occurences: 5 The below example is using all three parameters and returning result from the specified range. Python String Count() Method Example 4Output: occurences: 1 It can count non-alphabet chars also, see the below example. Python String Count() Method Example 5Output: occurences: 3 Next TopicPython Strings |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India