Computer Science
Write a program to count the number of times a character occurs in the given string.
Python
Python String Manipulation
80 Likes
Answer
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: KnowledgeBoat
Enter the character to count: e
e occurs 2 times
Answered By
30 Likes
Related Questions
What is the output produced?
(i) >>> "-".join(['123','365','1319'])
(ii) >>> " ".join(['Python', 'is', 'fun'])
Given a string S, write expressions to print
- first five characters of S
- Ninth character of S
- reversed S
- alternate characters from reversed S
Write a program which replaces all vowels in the string with '*'.
Write a program which reverses a string and stores the reversed string in a new string.