The for loop is commonly used to repeat some code a certain number of times. This is done by combining for loops with range objects.
------------------------------
ex.
for i in range(5):
print("hello!")
------------------------------
- Now if you wanted to check if the amount of a specific letter within a string.
ex2.
name = 'HEEEELLLLLOO THHERREE'
count = 0
for letter in name:
if letter == 'E':
count = count + 1
print(count)
7
Note: there are easier ways to count letters within a word through built-in tools such as 'HEEEELLLLLOO THHERREE'.count(βEβ)
FRANCNSTEIN Β© | Created ππππ β€
Top comments (0)