What is the String count() Method?

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

It is a very useful string function that can be used for string analysis.

Note: string count() function is case sensitive, meaning it will treat ‘a’ and ‘A’ different.

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