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

2007-05-03 Thread Steven Howe
Dave Borne wrote: Let's suppose s='12345 4343 454' How can I replace the last '4' character? If the last '4' will not always be the last character in the string, you could do: 'X'.join(s.rsplit('4',1)) from string import rfind def replaceLast_X_with_Y( s, x, y ): lastX =

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

2007-05-03 Thread kyosohma
On May 3, 9:44 am, Johny <[EMAIL PROTECTED]> wrote: > On May 3, 4:37 pm, [EMAIL PROTECTED] wrote: > > > > > 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

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

2007-05-03 Thread Dave Borne
> Let's suppose > s='12345 4343 454' > How can I replace the last '4' character? If the last '4' will not always be the last character in the string, you could do: 'X'.join(s.rsplit('4',1)) -Dave -- http://mail.python.org/mailman/listinfo/python-list

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

2007-05-03 Thread Grant Edwards
On 2007-05-03, Johny <[EMAIL PROTECTED]> 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

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

2007-05-03 Thread Matimus
On May 3, 7:44 am, Johny <[EMAIL PROTECTED]> wrote: > On May 3, 4:37 pm, [EMAIL PROTECTED] wrote: > > > > > 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

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

2007-05-03 Thread jay graves
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

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

2007-05-03 Thread Marc 'BlackJack' Rintsch
In <[EMAIL PROTECTED]>, Johny 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? Because you can't change strings. Any fun

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

2007-05-03 Thread Johny
On May 3, 4:37 pm, [EMAIL PROTECTED] wrote: > 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

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

2007-05-03 Thread kyosohma
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

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

2007-05-03 Thread Johny
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. -- http://mail.python.org/mailman/listinfo/python-list