On May 3, 9:27 am, Johny <[EMAIL PROTECTED]> wrote: > Let's suppose > s='12345 4343 454' > How can I replace the last '4' character? > I tried > string.replace(s,s[len(s)-1],'r') > where 'r' should replace the last '4'. > But it doesn't work. > Can anyone explain why? > > Thanks > L.
I think the reason it's not working is because you're doing it kind of backwards. For one thing, the "string" module is deprecated. I would do it like this: s = s.replace(s[len(s)-1], 'r') Although that is kind of hard to read. But it works. Mike -- http://mail.python.org/mailman/listinfo/python-list