Count the Number of Occurrences of a Character in a String in Python Using count()

(Last Updated On: 11/10/2023)

Python Program to Count the Number of Occurrences of a Character in a String Using count() Function

# Count the Number of Occurrences of a Character in String Using method count() in Python

my_string = "Hello"
my_char = "l"

print(my_string.count(my_char))

Output

2

Leave a Reply

Your email address will not be published. Required fields are marked *