I am trying to replace a character in a string using python. I am using a function called find_chr to find the location of the character that needs to be replaced.
def main():
s='IS GOING GO'
x='N'
y='a'
rep_chr(s,x,y)
def find_chr(s,char):
i=0
for ch in s:
if ch==char:
return (i)
break
i+=1
return -1
def rep_chr(s1,s2,s3):
return print(s1==s1[0:find_chr(s1,s2)]+s3+s1[(find_chr(s1,s2)+1):])
main()
My problem is that instead of getting the new string, the function is returning 'False'. I would appreciate any pointer to get the replaced string.
print(rep_chr(s,x,y))to(rep_chr(s,x,y))...str.replace? Just trying to recreate it for fun?