Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61264
| References | <27c0b454-62e9-410f-b05c-7c5fe306f8aa@googlegroups.com> |
|---|---|
| Date | 2013-12-08 12:05 +1100 |
| Subject | Re: Is It Bug? |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3713.1386464744.18130.python-list@python.org> (permalink) |
On Sun, Dec 8, 2013 at 11:59 AM, Mahan Marwat <mahanmarwat@gmail.com> wrote:
> Why this is not working.
>
>>>> 'Hello, \\\\World'.replace('\\', '\\')
>
> To me, Python will interpret '\\\\' to '\\'. And the replace method will replace '\\' with '\'. So, the result will be 'Hello, \World'. But it's give me 'Hello, \\\\World'.
>
> The result I want form the code is 'Hello, \World'.
You're replacing with the same as the source string. That's not going
to change anything.
The first thing to get your head around is Python string literals.
You'll find them well described in the online tutorial, or poke around
in the interactive interpreter. Once you master that, you should be
able to understand what you're trying to do here.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Is It Bug? Mahan Marwat <mahanmarwat@gmail.com> - 2013-12-07 16:59 -0800
Re: Is It Bug? Chris Angelico <rosuav@gmail.com> - 2013-12-08 12:05 +1100
Re: Is It Bug? Roy Smith <roy@panix.com> - 2013-12-07 20:22 -0500
Re: Is It Bug? Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-12-08 11:01 +0100
Re: Is It Bug? Chris Angelico <rosuav@gmail.com> - 2013-12-08 21:04 +1100
Re: Is It Bug? Chris Angelico <rosuav@gmail.com> - 2013-12-08 21:26 +1100
Re: Is It Bug? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-08 01:06 +0000
Re: Is It Bug? MRAB <python@mrabarnett.plus.com> - 2013-12-08 01:12 +0000
Re: Is It Bug? Tim Roberts <timr@probo.com> - 2013-12-07 22:53 -0800
Re: Is It Bug? Peter Otten <__peter__@web.de> - 2013-12-08 11:43 +0100
csiph-web