Python Program to Count the Number of Occurrences of a Character in a String Using Loops
# Count the Number of Occurrences of a Character in a String in Python using for loop
count = 0
my_string = "hello"
my_char = "l"
for i in my_string:
if i == my_char:
count += 1
print(count)
Output:
2
About The Author
I have more than 6 years of experience in the IT industry, and I have built a solid foundation in the creation and upkeep of online applications. I have constantly shown strong work ethics, self-motivation, and an aptitude for learning quickly throughout my career.