+ 1

Counting specific letter in string

How can I count number of a in "aioaeba"

10th May 2025, 5:44 PM
Suryansh
Suryansh - avatar
3 Antworten
+ 8
Alternatively, you could use the string method count(). Example: print("Lisa".count("i"))
10th May 2025, 6:13 PM
Lisa
Lisa - avatar
+ 3
In python, you would use a loop to go through your letters and if the letter matches "a", add it to a counter and then print it. e.g. counter = 0 loop: if letter == "a": counter += 1 print(counter)
10th May 2025, 6:10 PM
Ausgrindtube
Ausgrindtube - avatar
+ 1
Thank you Ausgrindtube and Lisa for help
10th May 2025, 6:16 PM
Suryansh
Suryansh - avatar