Hi,
Can someone tell me the difference between single quote and double
quote?
Thanks 21 2770 b8*******@yahoo.com wrote: Hi,
Can someone tell me the difference between single quote and double quote?
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/ b8*******@yahoo.com wrote: Hi,
Can someone tell me the difference between single quote and double quote? ord("'") - ord('"')
5
or ask a meaningful question ... b8*******@yahoo.com wrote: Hi,
Can someone tell me the difference between single quote and double quote?
Thanks
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.
John Machin wrote: b8*******@yahoo.com wrote:
Can someone tell me the difference between single quote and double quote?
>>> ord("'") - ord('"')
5
Very zen.
--
Michael Hoffman
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----- je****@unpythonic.net wrote: 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).
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 rk***@ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
Michael Hoffman wrote: John Machin wrote:
b8*******@yahoo.com wrote:
Can someone tell me the difference between single quote and double quote?
>>> ord("'") - ord('"') 5
Very zen.
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.
Steven D'Aprano wrote: Michael Hoffman wrote:
John Machin wrote:
b8*******@yahoo.com wrote:
Can someone tell me the difference between single quote and double quote?
>>> ord("'") - ord('"') 5
Very zen.
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.
It was a joke, I believe, not a serious answer.
--
Robert Kern rk***@ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
Steven D'Aprano wrote: Michael Hoffman wrote:John Machin wrote:b8*******@yahoo.com wrote: Can someone tell me the difference between single quote and double quote?
>>> ord("'") - ord('"') 5
Very zen.
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
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
On 2005-07-22, Steven D'Aprano <st***@REMOVEMEcyber.com.au> wrote: Can someone tell me the difference between single quote and double quote?
>>> ord("'") - ord('"') 5
Very zen.
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,
[...]
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 b8*******@yahoo.com wrote: Can someone tell me the difference between single quote and double quote?
One has double the fun.
--
Erik Max Francis && ma*@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
Steven D'Aprano wrote: Michael Hoffman wrote:
John Machin wrote:
b8*******@yahoo.com wrote:
Can someone tell me the difference between single quote and double quote?
>>> ord("'") - ord('"') 5
Very zen.
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.
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
Steven D'Aprano wrote: 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. sum(ord(c) for c in 'spaghetti marinara') - sum(ord(c) for c in
"spaghetti pescatora")
-119
Works for me... ;-)
[b8*******@yahoo.com] Can someone tell me the difference between single quote and double quote?
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
[Robert Kern] 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.
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
Peter Hansen wrote: Steven D'Aprano wrote:
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.
>>> sum(ord(c) for c in 'spaghetti marinara') - sum(ord(c) for c in "spaghetti pescatora") -119
Works for me... ;-)
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. a = foodstuff('spaghetti marinara') b = foodstuff('spaghetti pescatora') a - b
0 explain
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
On Friday 22 July 2005 08:09 am, François Pinard wrote: [Robert Kern] 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.
One sure thing is that it would help, later, if you ever want to internationalise a Python program. Not that it occurs that often! :-)
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
[Terry Hancock] On Friday 22 July 2005 08:09 am, François Pinard wrote:
[Robert Kern]
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.
One sure thing is that it would help, later, if you ever want to internationalise a Python program. Not that it occurs that often! :-)
Whoa. Why? Does xgettext not recognize _('')?
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
François Pinard wrote: There is no strong reason to use one and avoid the other. Yet, while representing strings, Python itself has a _preference_ for single quotes.
I use "double quoted strings" in almost all cases because I
think it's easier to see than 'single quoted quotes'.
Andrew da***@dalkescientific.com
Andrew Dalke said unto the world upon 2005-07-22 13:30: François Pinard wrote:
There is no strong reason to use one and avoid the other. Yet, while representing strings, Python itself has a _preference_ for single quotes.
I use "double quoted strings" in almost all cases because I think it's easier to see than 'single quoted quotes'.
Andrew da***@dalkescientific.com
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
On Fri, 22 Jul 2005 08:38:28 -0400, Peter Hansen wrote: Steven D'Aprano wrote: 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.
>>> sum(ord(c) for c in 'spaghetti marinara') - sum(ord(c) for c in "spaghetti pescatora") -119
Works for me... ;-)
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: import sets sets.Set("spaghetti marinara") - sets.Set("spaghetti pescatora")
Set(['m', 'n'])
--
Steven. This discussion thread is closed Replies have been disabled for this discussion. Similar topics
3 posts
views
Thread by Giulio |
last post: by
|
6 posts
views
Thread by XiongBin |
last post: by
|
5 posts
views
Thread by Bob |
last post: by
|
2 posts
views
Thread by Keith Smith |
last post: by
|
5 posts
views
Thread by Agnes |
last post: by
|
6 posts
views
Thread by John Pass |
last post: by
|
1 post
views
Thread by tankbattle |
last post: by
| |
6 posts
views
Thread by =?Utf-8?B?SmVmZg==?= |
last post: by
| | | | | | | | | | | |