Python program to calculate frequency of a characters in a string
Calculate the frequency of characters in a string
The string is a datatype in programing language and is formed when 2 or more characters join or concatenate together. Now it is not necessary for a string to have a distinct character, it can be meaningless or meaningful can have distinct characters or can be a combination of the same characters, Ex:- ‘abcd’, ‘aaaa’, ‘ababab’, ‘your_jokes’ this is a meaningless collection of characters but still are strings.
In this python program, we will be counting the frequency of a character in a string or how many times a character is present in a string.
- Step 1:- Start.
- Step 2:- Take user input as string.
- Step 3:- Taker user input of character.
- Step 4:- Initialize integer variable to get count.
- Step 5:- Use count function to count the frequency.
- Step 6:- Print counter variable
- Step 7:- End.
Python program to count frequency of a character in a string
#take user input String = input('Enter the string :') #take character input Character = input('Enter character :') #initiaalize int variable to store frequency frequency = 0 #use count function to count frequency of character frequency = String.count(Character) #count function is case sencetive #so it print frequency of Character according to given Character print(str(frequency) + ' is the frequency of given character')
Enter the string :Bagha
Enter Character :a
2 is the frequency of given character