Home >>Python String Methods >Python String count() Method

Python String count() Method

Python String count() Method

Python string count() method is used to return the number of times a particular value appears in the given input string.

Syntax:
string.count(value, start, end)

Parameter Values

Parameter Description
value This is a required parameter. It defines the string to value to search for.
start This is an optional parameter. It defines the position to start the search.
end This is an optional parameter. It defines the position to end the search.
Here is an example of Python count() method:

txt = "Here at PHPTPOINT we learn PHP and also work on the PHP projects"
x = txt.count("PHP")
print(x)

Output:
3
Example 2:

txt = "Here at PHPTPOINT we learn PHP and also work on the PHP projects"
x = txt.count("PHP", 10, 34)
print(x)

Output:
1

No Sidebar ads