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 =
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
> 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
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
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
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
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
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
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
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
10 matches
Mail list logo