2 Réponses
+ 3
Function replace does it:
https://www.tutorialspoint.com/JUMP_LINK__&&__python__&&__JUMP_LINK/string_replace.htm
In this case:
a = "hey"
print (a.replace('e','a'))
+ 3
Note that .replace will replace every 'e' in x with an 'a'. If x is 'heyes' and you use x.replace('e', 'a'), it will be 'hayas' afterwards. If you only want to replace the first 'e' in the string, use x.replace('e', 'a', 1) instead.
If you want to replace the second character no matter what (even if it's not an 'e'), you'll probably need something more complex like y = x[:1] + 'a' + x[2:].