What is this syntax ?

Laurent Claessens moky.math at gmail.com
Sun Jun 19 09:50:29 EDT 2011


Le 19/06/2011 15:41, candide a écrit :
> With Python 2.7 :
>
>   >>>  x="foo"
>   >>>  print '"'+x+'"'
> "foo"
>   >>>
>
>
> What is this curious syntax on line 2 ? Where is it documented ?

When you want to have an explicit double quote " in a string, you put in 
between single quote '.
(and vice versa)

So here you have the string
'"'
which is "
then
+x
(add x)
then
+'"'

Try also

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

Laurent



More information about the Python-list mailing list