Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7957

Re: What is this syntax ?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!news.le-studio75.com!news.univ-fcomte.fr!not-for-mail
From Laurent Claessens <moky.math@gmail.com>
Newsgroups comp.lang.python
Subject Re: What is this syntax ?
Date Sun, 19 Jun 2011 15:50:29 +0200
Organization A poorly-installed InterNetNews site
Lines 32
Message-ID <4DFDFEA5.9010204@gmail.com> (permalink)
References <4dfdfc99$0$715$426a34cc@news.free.fr>
NNTP-Posting-Host soleil.univ-fcomte.fr
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 8bit
X-Trace news.univ-fcomte.fr 1308491423 10861 194.57.84.1 (19 Jun 2011 13:50:23 GMT)
X-Complaints-To news@news.univ-fcomte.fr
NNTP-Posting-Date Sun, 19 Jun 2011 13:50:23 +0000 (UTC)
To candide <candide@free.invalid>
User-Agent Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.13) Gecko/20101208 Thunderbird/3.1.7
In-Reply-To <4dfdfc99$0$715$426a34cc@news.free.fr>
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7957

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

What is this syntax ? candide <candide@free.invalid> - 2011-06-19 15:41 +0200
  Re: What is this syntax ? Laurent Claessens <moky.math@gmail.com> - 2011-06-19 15:50 +0200
  Re: What is this syntax ? Noah Hall <enalicho@gmail.com> - 2011-06-19 14:58 +0100
  Re: What is this syntax ? Chris Angelico <rosuav@gmail.com> - 2011-06-20 00:03 +1000
  Re: What is this syntax ? candide <candide@free.invalid> - 2011-06-19 17:08 +0200
    Re: What is this syntax ? Roy Smith <roy@panix.com> - 2011-06-19 11:39 -0400
      Re: What is this syntax ? rusi <rustompmody@gmail.com> - 2011-06-19 09:58 -0700
        Re: What is this syntax ? Roy Smith <roy@panix.com> - 2011-06-19 16:20 -0400
          Re: What is this syntax ? Vito 'ZeD' De Tullio <zak.mc.kraken@libero.it> - 2011-06-19 23:06 +0200
            Re: What is this syntax ? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-06-19 23:19 +0000
              Re: What is this syntax ? Vito 'ZeD' De Tullio <zak.mc.kraken@libero.it> - 2011-06-20 07:42 +0200
          Re: What is this syntax ? Benjamin Kaplan <benjamin.kaplan@case.edu> - 2011-06-19 15:29 -0700

csiph-web