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
Hot today
What’s wrong?
3 Votes
Question is write a c program to print prime numbers up to n and print the largest number in array.
1 Votes
Error in Program
1 Votes
SQL
1 Votes
While loop
0 Votes