count() function in an inbuilt function in python programming language that returns the number of occurrences of a substring in the given string.
string.count(substring, start=…, end=…)
The count() function has one compulsory and two optional parameters.
1)substring – string whose count is to be found.
1)start (Optional) – starting index within the string where search starts.
2)end (Optional) – ending index within the string where search ends.
count() method returns an integer that denotes number of times a substring occurs in a given string.
Below is the Python implementation of the count() method without optional parameters:
Below is the Python implementation of the count() method using optional parameters.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course