How to replace the last (and only last) character in a string?

Grant Edwards grante at visi.com
Thu May 3 11:05:49 EDT 2007


On 2007-05-03, Johny <python at hope.cz> wrote:
> Let's suppose
> s='12345 4343 454'
> How can I replace the last '4' character?

>>> s = '12345 4343 454'
>>> s = s[:-1] + 'X'
>>> s
'12345 4343 45X'

-- 
Grant Edwards                   grante             Yow! Where's th' DAFFY
                                  at               DUCK EXHIBIT??
                               visi.com            



More information about the Python-list mailing list