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.
Contact Us