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?
Instead of doing it that way, you should use slicing. >>> s='12345 4343 454' >>> s = s[:-1] + 'r' >>> print s 12345 4343 45r >>> See http://docs.python.org/tut/node5.html#strings HTH. Jay Graves -- http://mail.python.org/mailman/listinfo/python-list