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.
- Python String Methods | Set 2 (len, count, center, ljust, rjust, isalpha, isalnum, isspace & join)
- Python | Count and display vowels in a string
- Python program to count number of vowels using sets in given string
- Python | Count all prefixes in given string with greatest frequency
- Python | Count the Number of matching characters in a pair of string
- Python | Count occurrences of a character in string
- Python | Ways to count number of substring in string
- Python | Count overlapping substring in a given string
- Python | Count String occurrences in mixed list
- Python - Count Strings with substring String List
- Python - Possible Substring count from String
- Python program to count the number of characters in a String
- String slicing in Python to check if a string can become empty by recursive deletion
- String slicing in Python to rotate a string
- Python | Check if a given string is binary string or not
- Python | Check if given string can be formed by concatenating string elements of list
- Python | Check if string ends with any string in given list
- Python | Sorting string using order defined by another string
- Python | Merge Tuple String List values to String
- Python | Sort each String in String list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.