I want to replace characters at the end of a python string. I have this string:
s = \"123123\"
I want to replace the last 2 with
2
>>> s = "aaa bbb aaa bbb" >>> s[::-1].replace('bbb','xxx',1)[::-1] 'aaa bbb aaa xxx'
For your second example
>>> s = "123123" >>> s[::-1].replace('2','x',1)[::-1] '1231x3'