How to use String count() Method

String count() method is very simple and straightforward to use. You just need to pass the substring as the parameter in function to count it’s number of occurrence. Let’s understand how to count string in Python with an example.

Python String count() Method

Python String count() function returns the number of occurrences of a substring within a String.

Python3




#initializing a string
my_string = "Apple"
#using string count() method
char_count = my_string.count('A')
#printing the result
print(char_count)


Output

1

In this article, we will explore the details of the count() method, exploring its syntax, usage, and some practical examples.

Similar Reads

What is the String count() Method?

...

String count() Method Syntax

String count() function is an inbuilt function in Python programming language that returns the number of occurrences of a substring in the given string....

How to use String count() Method

string. Count(substring, start= …., end= ….)...

More Example on String count() Method

...

Contact Us