What will be the for loop of this code? and can you tell a little description of the process by mentioning what does index and len mean here! Thank you.
def f3(word, letter):
index = 0
while index < len(word):
if word[index] == letter:
return index
index = index + 1
return -1
print(f3("processing", "s"))
print(f3("processing", "z"))
def f3(word,letter):
#index here is a counter variable used to ascertain if the condition is true or false
index = 0
#len is an inbuit python function that returns the length of a strig,list,e.t.c
while index < len(word):
if word[index] == letter:
return index
index = index + 1
return -1
print(f3('processing', 's'))
print(f3('processing', 'z'))
def f3(word, letter):
for i in word:
if i == letter:
return word.index(i)
return -1
print(f3('processing', 's'))
print(f3('processing', 'z'))
Comments