To count the occurrence of character or to find frequency of character in a string in python, you have to ask from user to enter a string and then ask to enter a character to count total occurrence of that character in the given string and finally print the result on the output screen as shown in the program given below.
Following python program ask from user to enter string and character to count occurrence of character in string or to find frequency of character in string:
# Python Program - Count Character in String while True: print("Enter 'x' for exit.") string = input("Enter any string: ") if string == 'x': break else: char = input("Enter a character to count: ") val = string.count(char) print(val,"\n")
Here is the sample run of the above Python program illustrating how to count total occurrence of particular character in a given string:
You may also like to learn or practice the same program in other popular programming languages: