Hello. Can anyone shed more light 💡 on this code. I really didn't understand it. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Hello. Can anyone shed more light 💡 on this code. I really didn't understand it.

https://code.sololearn.com/c35Rl46j2rs1/?ref=app

12th Dec 2020, 10:28 AM
Mas'ud Saleh
Mas'ud Saleh - avatar
2 Answers
+ 4
You can also use the built in method count() str = "testing for loops" print(str.count("t"))
12th Dec 2020, 3:05 PM
David Ashton
David Ashton - avatar
+ 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
12th Dec 2020, 10:32 AM
noteve
noteve - avatar