Count the Number of Occurrence of a Character in String

'''

Python Program to Count the Number of Occurrence of a Character in String

'''
count = 0

my_string = 'Captain America The First Avenger'

my_char = 'a'

for i in my_string:
    if i == my_char:
        count = count + 1


print("Total number of characters in the Word : ",count)

Comments