Is It Bug?

Roy Smith roy at panix.com
Sat Dec 7 20:22:41 EST 2013


In article <mailman.3713.1386464744.18130.python-list at python.org>,
 Chris Angelico <rosuav at gmail.com> wrote:

> 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. 

A couple of ideas to explore along those lines:

1) Read up on raw strings, i.e.

r'Hello, \World'

instead of 

'Hello, \\Word'

There's nothing you can do with raw strings that you can't do with 
regular strings, but they're easier to read when you start to use 
backslashes.

2) When in doubt about what I'm looking at in a string, I turn it into a 
list.  So, if I do:

>>> s = 'Hello, \\World'
>>> print s
Hello, \World

What is that character after the space?  Is it a backslash, or is it 
something that Python is printing as \W?  Not sure?  Just do:

>>> print list(s)
['H', 'e', 'l', 'l', 'o', ',', ' ', '\\', 'W', 'o', 'r', 'l', 'd']

and it's immediately obvious which it is.



More information about the Python-list mailing list