473,406 Members | 2,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

apostrophe or double quote?

Huy
I've been unable to find information clarifying this but. What is the
difference between 'somestring' and "somestring"? When I use type() it
still reports as string. If there is a difference could someone point
me to documentation or explain when to use and when not to? Hope I
sound clear.

Feb 8 '06 #1
9 9372
Huy wrote:
I've been unable to find information clarifying this but. What is the
difference between 'somestring' and "somestring"? When I use type() it
still reports as string. If there is a difference could someone point
me to documentation or explain when to use and when not to? Hope I
sound clear.


There is no difference. However, compare the following:

py> 'internal quotes: "'
'internal quotes: "'
py> "internal apostrophe: '"
"internal apostrophe: '"
py> 'astring'
'astring'
py> "astring"
'astring'

Feb 8 '06 #2
Huy wrote:
I've been unable to find information clarifying this but. What is the
difference between 'somestring' and "somestring"? When I use type() it
still reports as string. If there is a difference could someone point
me to documentation or explain when to use and when not to? Hope I
sound clear.

It's just easier to have two permitted string quotes. That way, if your
string has an apostrophe in it you can say

s = "it's"

and if it has a double quote in it you can say

s = 'The double quote (") rules'

So there's really no difference at all. You can also use escaping to
achieve the same end:

s = "The double quote (\") rules"

if you prefer.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Feb 8 '06 #3
Steve Holden wrote:
It's just easier to have two permitted string quotes. That way, if your
string has an apostrophe in it you can say

s = "it's"


It's particularly handy if you are building strings of a language that
already has its own quotes, e.g. SQL or XML:

sql_snippet = " where name='Max'"
html_snippet = ' align="left"'

-- Christoph
Feb 8 '06 #4
Steve Holden <st***@holdenweb.com> wrote:
Huy wrote:
I've been unable to find information clarifying this but. What is the
difference between 'somestring' and "somestring"?

It's just easier to have two permitted string quotes. That way, if your
string has an apostrophe in it you can say

s = "it's"

and if it has a double quote in it you can say

s = 'The double quote (") rules'

So there's really no difference at all. You can also use escaping to
achieve the same end:

s = "The double quote (\") rules"

if you prefer.


Or triple quoting:

s = """The double quote (") rules"""
I've seen someone around here use 'somestring' for internal values
(dict keys and the like) and "somestring" for values being shown to
the user, so it's easy(ish) to tell what may need translating or
can otherwise safely be changed. I like this convention (provided
it remains a convention).

--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump
Feb 8 '06 #5
Huy
Thank you for all your help; it makes perfect sense now.

Feb 8 '06 #6
Just to present a complete picture, not mentioned in this thread are
triple-quoted strings:

'abc' == '''abc''' == "abc" == """abc"""

Triple-quoted strings are no different than regular strings, though they do
allow literal newlines to be embedded in the string. Their presence is most
often detected in doc strings precisely for this reason.

Skip
Feb 8 '06 #7
On Wed, 8 Feb 2006 11:57:00 -0600
sk**@pobox.com wrote:
Just to present a complete picture, not mentioned in this
thread are triple-quoted strings:

'abc' == '''abc''' == "abc" == """abc"""

Triple-quoted strings are no different than regular
strings, though they do allow literal newlines to be
embedded in the string. Their presence is most often
detected in doc strings precisely for this reason.


Also in the mode of beating a dead horse ... ;-)

Some people prefer to use single quotes for 'labels' (i.e. a
name which is meaningful to the program, but not to the
user), and reserve either double-quotes or
triple-double-quotes for text to be shown to the user. This
tends to make things slightly easier when you have to go
back and use gettext to internationalize your code.

But that's a matter of taste.

It is interesting to note, however, that the Python repr()
function prefers to use single quotes, using double quotes
only when a single quote is embedded in the string.

Cheers,
Terry
--
Terry Hancock (ha*****@AnansiSpaceworks.com)
Anansi Spaceworks http://www.AnansiSpaceworks.com

Feb 8 '06 #8
Terry Hancock <ha*****@anansispaceworks.com> wrote:
sk**@pobox.com wrote:
Just to present a complete picture, not mentioned in this
thread are triple-quoted strings:
[ ... ]

Also in the mode of beating a dead horse ... ;-)

Some people prefer to use single quotes for 'labels' (i.e. a
name which is meaningful to the program, but not to the
user), and reserve either double-quotes or
triple-double-quotes for text to be shown to the user.
[ ... ]


Hmm, I made both these points a couple of posts upthread, but
it didn't appear to get through the news->mail gateway.

--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomež se bera eadward ofdun hlęddre heafdes bęce bump bump bump
Feb 9 '06 #9
On 09 Feb 2006 12:54:04 +0000 (GMT)
Sion Arrowsmith <si***@chiark.greenend.org.uk> wrote:
Terry Hancock <ha*****@anansispaceworks.com> wrote:
sk**@pobox.com wrote:
Just to present a complete picture, not mentioned in

this > thread are triple-quoted strings:
[ ... ]

Also in the mode of beating a dead horse ... ;-)

Some people prefer to use single quotes for 'labels'
(i.e. a name which is meaningful to the program, but not
to the user), and reserve either double-quotes or
triple-double-quotes for text to be shown to the user.
[ ... ]


Hmm, I made both these points a couple of posts upthread,
but it didn't appear to get through the news->mail
gateway.


Ah well, it all came up on the list about a month or two ago
anyway (I guess. I don't know, maybe it was a year ago), so
I'm just repeating it.

--
Terry Hancock (ha*****@AnansiSpaceworks.com)
Anansi Spaceworks http://www.AnansiSpaceworks.com

Feb 10 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Joshua Beall | last post by:
Hi All, I have heard other people say that PHP can parse double quoted strings (e.g., "Hello, World") faster than it can parse single quoted strings (e.g., 'Hello, World'). This seems backwards...
1
by: Joel | last post by:
Gentlemen, Is there a way to use an inStr function to test for a double quote?
4
by: Alden Streeter | last post by:
Here is the HTML that is being output by my asp page: <a href='Files/category/computers/bigimages/computers-sub-monitors.jpg' target='_blank' onMouseOver="window.status='Click for a larger image...
2
by: Diarmaid McGleenan | last post by:
Hi all. This isn't quite the same single/double-quote problem we see posted a multitude of times in this ng. Read on... I have a js function called ShowActiveLink which accepts a string...
8
by: Ahmad A. Rahman | last post by:
Hi all, I have a problem constructing a regular expression using .net. I have a string, separated with comma, and I want to group the string together but, I failed to group a numeric character...
4
by: fred | last post by:
Hi, is there a way to put " (double quote) into a verbatin string? thank you
4
by: Kevin Thomas | last post by:
Hi there, If I have a string var, strFoo that contains double-quotes such that it looks like this: I "love" VB What do I pass into the "replace" method to replace the double-quotes with...
5
by: Frank | last post by:
How do I include a double quote in a string displayed on the screen? I tried: wsprintf(szBuffer, "%s's ""%s"" preferences retrieved" But no quotes showed.
4
by: zacks | last post by:
I need to check the current value of a string value to see if it either starts with or ends with a double quote character, as in "123" (where the quotes are actual contens of the string). I thought...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.