Python program to Count Occurrence of a Character in a String

str = input("Enter the string: ")
ch = input("Enter the character to count: ");
c = str.count(ch)
print(ch, "occurs", c, "times")

OUTPUT:

Enter the string: chaselearn
Enter the character to count: a
a occurs 2 times

Sharing Is Caring

Leave a Comment