Hi all I struglle with this code in python. I try to make a function that can find a world from a phrase.
Function look like this :
def find(strng,ch):
... index=0
... while index<len(strng):
... if strng[index]==ch:
... return index
... index=+1
... return-1
What i posted is copy/paste more from a book but I dont understand basically what does when I write this : "if strng[index]==ch" more exactlly why is put "index" in this type of parantheses? From what I learn this paranthese[ ] is use for list and to find element from a world for example s="ban" then s[0] will be =b but now in function I dont know why use this paranthese and what purpose have index here. Can someone explain please? thank
Function look like this :
def find(strng,ch):
... index=0
... while index<len(strng):
... if strng[index]==ch:
... return index
... index=+1
... return-1
What i posted is copy/paste more from a book but I dont understand basically what does when I write this : "if strng[index]==ch" more exactlly why is put "index" in this type of parantheses? From what I learn this paranthese[ ] is use for list and to find element from a world for example s="ban" then s[0] will be =b but now in function I dont know why use this paranthese and what purpose have index here. Can someone explain please? thank