[Tutor] trouble reading Programming Python

rob@jam.rr.com rob@jam.rr.com
Thu, 19 Apr 2001 21:20:13 -0500


Although I'm not sure why that first " is in there, it's as protected as
it needs to be due to the fact that it appears between two single
quotes. Everything between those single quotes is to be printed,
including each double quote sign, such as in the following:

>>> print '"""""'
"""""

If you place single quotes inside a pair of double quotes, the same
thing happens:

>>> print "'''''"
'''''

You can use either single or double quotes for containment, and
sometimes it doesn't matter which you choose. However, there are
circumstances in which one will work but the other will not, such as in
these examples:

>>> print 'quoth the Raven "nevermore"'
quoth the Raven "nevermore"
>>> print "quoth the Raven "nevermore""
Traceback (  File "<interactive input>", line 1
    print "quoth the Raven "nevermore""
                                    ^
SyntaxError: invalid syntax

>>> print "I can't see!"
I can't see!
>>> print 'I can't see!'
Traceback (  File "<interactive input>", line 1
    print 'I can't see!'
                 ^
SyntaxError: invalid syntax

I hope this helps,
Rob

jonsoons@telocity.com wrote:
> 
> I am on page 47 of "Programming Python" 2nd Edition
> and 3/4 of the way down the page there are a couple
> of lines with three double quotes within:
> 
> print 'Got this" "%s"' % raw_input()
> 
> and
> 
> Got this" "Help! Help! I'm being repressed!"
> 
> It all makes sense apart from the first " in
> each line. Are these characters protected from
> interpretation in some way that the %s is not?
> Why is this not a syntax error?
> 
> To quote the manual: "...r"\" is a valid string
> literal, r"\"" is not..."
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 

Useless Python!
If your Python is this useless, we need you.
http://www.lowerstandard.com/python/pythonsource.html