0
Hello. Can anyone shed more light đĄ on this code. I really didn't understand it.
2 Answers
+ 4
You can also use the built in method count()
str = "testing for loops"
print(str.count("t"))
+ 2
It is counting the character "t"
The "for" loop is to iterate every letter in a string (one by one).
The "if" checks if the elements iterated by the "for" loop matches the letter.
If it matches the condition, the value of "count" will be added by 1
Therefore, the "count" variable means the number of that letter in the string
See this for visualizationđ
https://code.sololearn.com/cwICMIjMV9m4/?ref=app