Python String Count() Method
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.
It returns number of occurrences of substring in the range.
Let's see some examples to understand the count() method.
Python String Count() Method Example 1
Python String Count() Method Example 2
Here, we are passing second parameter (start index).
Python String Count() Method Example 3
The below example is using all three parameters and returning result from the specified range.
Python String Count() Method Example 4
It can count non-alphabet chars also, see the below example.
Python String Count() Method Example 5
JavaTpoint offers too many high quality services. Mail us on [email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected]
Duration: 1 week to 2 week