Difference between " and ' | | |
Hi,
Can someone tell me the difference between single quote and double
quote?
Thanks | | | | re: Difference between " and ' b83503104@yahoo.com wrote:
[color=blue]
> Hi,
>
> Can someone tell me the difference between single quote and double
> quote?[/color]
There is none. Except that in a double quoted string, single quotes don't
have to be escaped and vice versa, sometimes one of the two forms saves you
some backslashes:
"That's my house" == 'That\'s my house'
"You say: \"Hello\"" == 'You say: "Hello"'
--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/ | | | | re: Difference between " and ' b83503104@yahoo.com wrote:[color=blue]
> Hi,
>
> Can someone tell me the difference between single quote and double
> quote?[/color]
[color=blue][color=green][color=darkred]
>>> ord("'") - ord('"')[/color][/color][/color]
5
or ask a meaningful question ... | | | | re: Difference between " and ' b83503104@yahoo.com wrote:[color=blue]
> Hi,
>
> Can someone tell me the difference between single quote and double
> quote?
>
> Thanks[/color]
And please settle the dispute between "xxx". And "xxx".
There was a fellow at Oxford who decided these things but I hear he
went mad. | | | | re: Difference between " and '
John Machin wrote:[color=blue]
> b83503104@yahoo.com wrote:
>[color=green]
>> Can someone tell me the difference between single quote and double
>> quote?[/color]
>[color=green][color=darkred]
> >>> ord("'") - ord('"')[/color][/color]
> 5[/color]
Very zen.
--
Michael Hoffman | | | | re: Difference between " and '
The only difference is when you want to include " or ' inside the string. If
you want to include the "like" quote, then escape it ("\"", '\''). If you
include the "unlike" quote, no escape is needed ("'" or '"').
I think that people new to programming will use '' if it is unshifted on their
keyboards. People from a "C" background may use "" for strings (since in that
language, '' is for a single character only).
Jeff
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
iD8DBQFC4EawJd01MZaTXX0RAtj2AJ0R7WBfyZbE52R5iRMQ79 FUQTeW/QCfQUgI
KZM0i2tJdpoKBeALs/uORQs=
=+5U2
-----END PGP SIGNATURE----- | | | | re: Difference between " and ' jepler@unpythonic.net wrote:[color=blue]
> The only difference is when you want to include " or ' inside the string. If
> you want to include the "like" quote, then escape it ("\"", '\''). If you
> include the "unlike" quote, no escape is needed ("'" or '"').
>
> I think that people new to programming will use '' if it is unshifted on their
> keyboards. People from a "C" background may use "" for strings (since in that
> language, '' is for a single character only).[/color]
I find that I switch between the two pretty freely. One habit that seems
to crop up, though, is that I will use '' for internal strings and ""
for strings that will eventually get seen by the user.
Don't ask me why.
--
Robert Kern rkern@ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter | | | | re: Difference between " and '
Michael Hoffman wrote:[color=blue]
> John Machin wrote:
>[color=green]
>> b83503104@yahoo.com wrote:
>>[color=darkred]
>>> Can someone tell me the difference between single quote and double
>>> quote?[/color]
>>[color=darkred]
>> >>> ord("'") - ord('"')[/color]
>> 5[/color]
>
> Very zen.[/color]
But unfortunately incorrect, since the original poster
didn't ask for the difference between the ordinal
values of the single quote and double quote characters,
but for the difference between the characters themselves.
The question was in plain English, and in my opinion,
perfectly understandable, especially since some common
programming languages do have significant differences
between single-quoted strings and double-quoted strings.
It may shock some people to learn that difference in
the sense of mathematical subtraction is not the only
meaning of the word, but there it is. One wouldn't, I
hope, misunderstand "What is the difference between
spaghetti marinara and spaghetti pescatora?" and
attempt to subtract one from the other, since
subtraction is not defined for foodstuffs.
--
Steven. | | | | re: Difference between " and '
Steven D'Aprano wrote:[color=blue]
> Michael Hoffman wrote:
>[color=green]
>>John Machin wrote:
>>[color=darkred]
>>>b83503104@yahoo.com wrote:
>>>
>>>>Can someone tell me the difference between single quote and double
>>>>quote?
>>>
>>> >>> ord("'") - ord('"')
>>>5[/color]
>>
>>Very zen.[/color]
>
> But unfortunately incorrect, since the original poster
> didn't ask for the difference between the ordinal
> values of the single quote and double quote characters,
> but for the difference between the characters themselves.[/color]
It was a joke, I believe, not a serious answer.
--
Robert Kern rkern@ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter | | | | re: Difference between " and '
Steven D'Aprano wrote:[color=blue]
> Michael Hoffman wrote:[color=green]
>>John Machin wrote:[color=darkred]
>>>b83503104@yahoo.com wrote:
>>>>Can someone tell me the difference between single quote and double
>>>>quote?[/color][/color][/color]
[color=blue][color=green][color=darkred]
>>> >>> ord("'") - ord('"')
>>>5[/color][/color][/color]
[color=blue][color=green]
>>Very zen.[/color][/color]
[color=blue]
> But unfortunately incorrect, since the original poster
> didn't ask for the difference between the ordinal
> values of the single quote and double quote characters[/color]
Steven, your reply was one of the most subtle and hilarious things I've
read in a long time. Unfortunately I couldn't tell if it was
intentional or not. :)
--
Benji York | | | | re: Difference between " and '
On 2005-07-22, Steven D'Aprano <steve@REMOVEMEcyber.com.au> wrote:
[color=blue][color=green][color=darkred]
>>>> Can someone tell me the difference between single quote and double
>>>> quote?
>>>
>>> >>> ord("'") - ord('"')
>>> 5[/color]
>>
>> Very zen.[/color]
>
> But unfortunately incorrect, since the original poster
> didn't ask for the difference between the ordinal
> values of the single quote and double quote characters,[/color]
[...]
It's a, I say it's a _joke_ son. Don't cha get it? You're
built too short, the good ones go over yer head. Ya got a
hole in yer glove, boy, I keep pitching them and you keep
missing them. Ya gotta keep yer eye on the ball, son. Eye.
Ball. Eyeball. I almost had a funny there. Joke, that is.
--
Grant Edwards grante Yow! Gibble, Gobble, we
at ACCEPT YOU...
visi.com | | | | re: Difference between " and ' b83503104@yahoo.com wrote:
[color=blue]
> Can someone tell me the difference between single quote and double
> quote?[/color]
One has double the fun.
--
Erik Max Francis && max@alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
Forgive your enemies, but never forget their names.
-- John F. Kennedy | | | | re: Difference between " and '
Steven D'Aprano wrote:[color=blue]
> Michael Hoffman wrote:
>[color=green]
>> John Machin wrote:
>>[color=darkred]
>>> b83503104@yahoo.com wrote:
>>>
>>>> Can someone tell me the difference between single quote and double
>>>> quote?
>>>
>>> >>> ord("'") - ord('"')
>>> 5[/color]
>>
>> Very zen.[/color]
>
> But unfortunately incorrect, since the original poster didn't ask for
> the difference between the ordinal values of the single quote and double
> quote characters, but for the difference between the characters themselves.[/color]
It reminded me of a zen koan, because although it was a joke at the
expense of original poster, the true answer was still contained within
when the answerer had to use different kinds of quoting to quote single
and double quotes.
--
Michael Hoffman | | | | re: Difference between " and '
Steven D'Aprano wrote:[color=blue]
> It may shock some people to learn that difference in the sense of
> mathematical subtraction is not the only meaning of the word, but there
> it is. One wouldn't, I hope, misunderstand "What is the difference
> between spaghetti marinara and spaghetti pescatora?" and attempt to
> subtract one from the other, since subtraction is not defined for
> foodstuffs.[/color]
[color=blue][color=green][color=darkred]
>>> sum(ord(c) for c in 'spaghetti marinara') - sum(ord(c) for c in[/color][/color][/color]
"spaghetti pescatora")
-119
Works for me... ;-) | | | | re: Difference between " and '
[b83503104@yahoo.com]
[color=blue]
> Can someone tell me the difference between single quote and double
> quote?[/color]
There is no strong reason to use one and avoid the other. Yet, while
representing strings, Python itself has a _preference_ for single
quotes. Programmers can put this duality to good use, by adopting
reasonable conventions, which are nothing more than conventions! :-)
I would guess many people choose one over the other for minimizing the
amount of backslash escape needed. Some people keep double quotes for
strings that would later undergo formatting, maybe because in most
shells and some other languages, double quotes allow for substitution
and single quotes prevent it. But in my opinion, while not dismissing
a lot of wisdom developed within other languages, it may be foolish
letting other languages blindly dictate what is best Python style.
Personally, I keep single quotes for "computer" strings, and double
quotes for "human" strings. To segregate between "computer" and "human"
character for a string, I merely ask myself: "If I wanted to use this
program in another language, would I want this particular string
translated or not?". Yes means double quotes, no means single quotes.
As single quotes are often use within human text, as apostrophes, this
was a wise choice as far as shell escaping goes.
This is extendable to triple-quoted strings. I use triple-double quotes
for doc strings meant to hold documentation, which is the usual case.
If doc strings are used for BNF snippets, like with SPARK, or any other
machine data, triple-single quotes are mandatory by my own convention.
--
François Pinard http://pinard.progiciels-bpi.ca | | | | re: Difference between " and '
[Robert Kern]
[color=blue]
> One habit that seems to crop up, though, is that I will use '' for
> internal strings and "" for strings that will eventually get seen by
> the user. Don't ask me why.[/color]
One sure thing is that it would help, later, if you ever want to
internationalise a Python program. Not that it occurs that often! :-)
--
François Pinard http://pinard.progiciels-bpi.ca | | | | re: Difference between " and '
Peter Hansen wrote:[color=blue]
> Steven D'Aprano wrote:
>[color=green]
>> It may shock some people to learn that difference in the sense of
>> mathematical subtraction is not the only meaning of the word, but
>> there it is. One wouldn't, I hope, misunderstand "What is the
>> difference between spaghetti marinara and spaghetti pescatora?" and
>> attempt to subtract one from the other, since subtraction is not
>> defined for foodstuffs.[/color]
>
>[color=green][color=darkred]
> >>> sum(ord(c) for c in 'spaghetti marinara') - sum(ord(c) for c in[/color][/color]
> "spaghetti pescatora")
> -119
>
> Works for me... ;-)[/color]
Works for me too:
C:\junk>python --fuzzy --punt
Python 9.4.1 (#165, Mar 30 3005, 09:13:57) [MSC v.13109 1024 bit
(Intel)] on win1024
Type "help", "copyright", "credits" or "license" for more information.[color=blue][color=green][color=darkred]
>>> a = foodstuff('spaghetti marinara')
>>> b = foodstuff('spaghetti pescatora')
>>> a - b[/color][/color][/color]
0[color=blue][color=green][color=darkred]
>>> explain[/color][/color][/color]
a.base is b.base
a.topping != b.topping
but
fuzzy mode selected
a.topping isa salty_smelly_stuff
b.topping isa salty_smelly_stuff
punt mode selected
prob(customer_knows_difference) = 0.01
PSF interdiction
all your operator are belong to us | | | | re: Difference between " and '
On Friday 22 July 2005 08:09 am, François Pinard wrote:[color=blue]
> [Robert Kern][color=green]
> > One habit that seems to crop up, though, is that I will use '' for
> > internal strings and "" for strings that will eventually get seen by
> > the user. Don't ask me why.[/color]
>
> One sure thing is that it would help, later, if you ever want to
> internationalise a Python program. Not that it occurs that often! :-)[/color]
Whoa. Why? Does xgettext not recognize _('')? I'm just learning
to use it. Maybe I should pay attention to this point if that's so.
--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks http://www.anansispaceworks.com | | | | re: Difference between " and '
[Terry Hancock]
[color=blue]
> On Friday 22 July 2005 08:09 am, François Pinard wrote:
>[color=green]
> > [Robert Kern]
> >[color=darkred]
> > > One habit that seems to crop up, though, is that I will use '' for
> > > internal strings and "" for strings that will eventually get seen
> > > by the user. Don't ask me why.[/color][/color][/color]
[color=blue][color=green]
> > One sure thing is that it would help, later, if you ever want to
> > internationalise a Python program. Not that it occurs that often! :-)[/color][/color]
[color=blue]
> Whoa. Why? Does xgettext not recognize _('')?[/color]
Yes, of course.
The most tedious part of internationalising a project is the selection
of strings to be translated, among all program strings, and wrapping
these within the special _(...) construct. If you can _already_ rely
on the fact double-quote strings are always to be wrapped, and that
single-quote strings are never to be wrapped, the tedious part is
already done, or almost. A few relatively quick editor commands are
may complete that aspect of the work (provided you use a reasonably
featureful editor).
As for Using xgettext or its Python counterpart, this is usually burned
into the release engineering (Makefile, distutils, or else), and is not
much of an effort, once you found a good recipe or example for it.
--
François Pinard http://pinard.progiciels-bpi.ca | | | | re: Difference between " and '
François Pinard wrote:[color=blue]
> There is no strong reason to use one and avoid the other. Yet, while
> representing strings, Python itself has a _preference_ for single
> quotes.[/color]
I use "double quoted strings" in almost all cases because I
think it's easier to see than 'single quoted quotes'.
Andrew dalke@dalkescientific.com | | | | re: Difference between " and '
Andrew Dalke said unto the world upon 2005-07-22 13:30:[color=blue]
> François Pinard wrote:
>[color=green]
>>There is no strong reason to use one and avoid the other. Yet, while
>>representing strings, Python itself has a _preference_ for single
>>quotes.[/color]
>
>
> I use "double quoted strings" in almost all cases because I
> think it's easier to see than 'single quoted quotes'.
>
> Andrew
> dalke@dalkescientific.com
>[/color]
I prefer the look of '''single triple''' to """double triple""" but a
while back I noticed pydoc doesn't work as well with single triple
quotes. When I posted here, Kent Johnson was kind enough to tease out
of me what I was on about and file a bug:
<http://sourceforge.net/tracker/index.php?func=detail&aid=1185124&group_id=5470&at id=105470>
Best to all,
Brian vdB | | | | re: Difference between " and '
On Fri, 22 Jul 2005 08:38:28 -0400, Peter Hansen wrote:
[color=blue]
> Steven D'Aprano wrote:[color=green]
>> It may shock some people to learn that difference in the sense of
>> mathematical subtraction is not the only meaning of the word, but there
>> it is. One wouldn't, I hope, misunderstand "What is the difference
>> between spaghetti marinara and spaghetti pescatora?" and attempt to
>> subtract one from the other, since subtraction is not defined for
>> foodstuffs.[/color]
>[color=green][color=darkred]
> >>> sum(ord(c) for c in 'spaghetti marinara') - sum(ord(c) for c in[/color][/color]
> "spaghetti pescatora")
> -119
>
> Works for me... ;-)[/color]
Yes, but if you had thought about the problem a little longer, you would
have removed the spaghetti from both, since they just cancel each other.
Although that does assume that the commutative law holds for pasta
products.
Personally, I prefer this answer:
[color=blue][color=green][color=darkred]
>>> import sets
>>> sets.Set("spaghetti marinara") - sets.Set("spaghetti pescatora")[/color][/color][/color]
Set(['m', 'n'])
--
Steven. |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,327 network members.
|