Str.count will return the number of non-overlapping occurrences of substring or object in string.

How many times an object is coming in given string for example in apple p is coming 2 times.Lets see how to write it in python.Let us suppose apple as string a.

a='Apple'

a.count('p',0,5)

Output: 2

Syntax of Str.count

a.count(sub, start, end)

sub=It is substring or an object(p in this case) which occurrence in a string(a in this case) to count.

start=It is starting index of string.

end=It is ending index of string or the last element.

Start to end is value of index in which value of substring is to count.

String count in python
Str.count

 

By SC

One thought on “Str.Count”

Comments are closed.