Difference between double and single quotes
John Grayson
johngrayson at home.com
Tue Aug 1 07:04:57 EDT 2000
In article <8m64ij$f2k$1 at nnrp1.deja.com>,
pauljolly at my-deja.com wrote:
> Dear All,
>
> Please can someone tell me whether Python distinguishes between double
> and single quotes in any way? This was brought to my attention by a
> friend who queried my use of double and single quotes, saying that in
> the UNIX shell a distinction is made.
>
> Many thanks in advance.
>
> Regards
>
> Paul Jolly
>
Single and double quotes may be freely interchanged (so long as
they are balanced %-) ). It is easy, therefore, to construct strings
containing either single or double quotes.
"It's" 'quote "xxx"'
lst = ['1', "2", '3'] is equivalent to lst = ["1", '2', "3"]
If you are constructing command strings to use in Unix, then it can
be very convenient. Note that you may still need to escape occasional
quotes...
look4 = 'file'
word_count = os.popen("grep 'open(%s \"rb\")' *.py | wc" % look4)
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
More information about the Python-list
mailing list