Adding an end parameter in Python -


i've got issues adding "end" parameter function searches specific letter in string.

this code far:

def find(str, ch, start=0):    index = start   while index < len(str): if str[index] == ch:    return index  index = index + 1  return -1 

i know cannot use len() parameter because defined during def process , not when call on find function. cannot useful because length of string not established during def.

thank answers/answer.

you add end parameter this:

def find(string, ch, start, end):      index = start     while index <= end:            #check if reaches 'end' parameter         if string[index] == ch:              return index          index = index + 1         if index > len(string):             break                  #break if index greater len(string)     return -1 

demo:

>>> find('testing123','1',0,9) 7 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -