My question is very simple, but I didn't get the answer from google.
There is a python string:
s = "123123"
I want to replace the last 2
with x
. Suppose there is a method called replace_last
:
r = replace_last(s, '2', 'x')
print r
1231x3
Is there any built-in or easy method to do this?
UPDATE
Sorry, guys, since someone said my example is not clear, I just edited my example, but not quickly enough.
What I want is just replace a string with another string once, its similar with python's:
string.replace('a', 'b', 1)
But is from the end to beginning.