473,385 Members | 1,764 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,385 software developers and data experts.

Why """, not '''?

Why is """ the preferred delimiter for multi-line strings?
Mar 5 '08 #1
8 1259
On Mar 5, 9:56 am, MartinRineh...@gmail.com wrote:
Why is """ the preferred delimiter for multi-line strings?
Is it ? FWIW, I use single quotes whenever I can and double whenever I
have to (i.e. rarely).

George
Mar 5 '08 #2
On Wed, 5 Mar 2008 06:56:24 -0800 (PST)
Ma************@gmail.com wrote:
Why is """ the preferred delimiter for multi-line strings?
Where did you see that? The only place I saw it was the style guide
and it was only talking about docstrings. Even there they used """ as
an example but the text talked about using triple quotes as opposed to
single quotes even when it is a single line docstring. I don't think
that there is any preference for """ over ''' in general. Pick one for
consistiency.

Note however that """ can't be confused with " followed by ' as in "'A'
is the first letter of the alphabet."

--
D'Arcy J.M. Cain <da***@druid.net | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
Mar 5 '08 #3


D'Arcy J.M. Cain wrote:
Where did you see that? The only place I saw it was the style guide
and it was only talking about docstrings.
PEP 8 and 257, and you're right, they are both about docstrings.

Also, I'd never seen an example of the triple apostrophe form until I
dove
into the formal syntax specification.
Mar 5 '08 #4
<Ma************@gmail.comwrote:
Why is """ the preferred delimiter for multi-line strings?
One advantage is that a dumb syntax highlighter is more likely to cope
well if the content includes an apostrophe.

-M-
Mar 5 '08 #5
On Wed, 05 Mar 2008 19:19:08 +0000, Matthew Woodcraft wrote:
<Ma************@gmail.comwrote:
>Why is """ the preferred delimiter for multi-line strings?

One advantage is that a dumb syntax highlighter is more likely to cope
well if the content includes an apostrophe.
But if the content contains double-quote marks, the "dumb syntax
highligher" is more likely to cope well if you use '''. And, let's be
realistic here, a "dumb syntax highlighter" is more likely to not cope
well with triple-quote strings *at all*.

Python treats ' and " symmetrically. There is no difference between them,
except that:

(1) to type " requires using the shift-key, typing ' does not (on English
QWERTY keyboards at least);

(2) in some typefaces " (double-quote) may be confused with '' (two
single-quotes); and

(3) they look different.

Pretty basic stuff really.
--
Steven
Mar 5 '08 #6
Steven D'Aprano <st***@REMOVE-THIS-cybersource.com.auwrote:
>On Wed, 05 Mar 2008 19:19:08 +0000, Matthew Woodcraft wrote:
>One advantage is that a dumb syntax highlighter is more likely to cope
well if the content includes an apostrophe.
But if the content contains double-quote marks, the "dumb syntax
highligher" is more likely to cope well if you use '''.
That's right. But apostrophes are rather more common than quote marks
in English text.
And, let's be realistic here, a "dumb syntax highlighter" is more
likely to not cope well with triple-quote strings *at all*.
In practice they often do the right thing, what with three being an odd
number.

-M-
Mar 5 '08 #7
On Wed, 05 Mar 2008 23:27:21 +0000, Matthew Woodcraft wrote:
Steven D'Aprano <st***@REMOVE-THIS-cybersource.com.auwrote:
>>On Wed, 05 Mar 2008 19:19:08 +0000, Matthew Woodcraft wrote:
>>One advantage is that a dumb syntax highlighter is more likely to cope
well if the content includes an apostrophe.
>But if the content contains double-quote marks, the "dumb syntax
highligher" is more likely to cope well if you use '''.

That's right. But apostrophes are rather more common than quote marks in
English text.
Surely it would depend on the type of text: pick up any random English
novel containing dialogue, and you're likely to find a couple of dozen
pairs of quotation marks per page, against a few apostrophes.

--
Steven
Mar 6 '08 #8
Steven D'Aprano wrote:
Surely it would depend on the type of text: pick up any random English
novel containing dialogue, and you're likely to find a couple of dozen
pairs of quotation marks per page, against a few apostrophes.
That's an idea... Write a novel in Python docstrings.

Someone make me go to bed now.
--
Mar 6 '08 #9

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

Similar topics

43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
1
by: David Furey | last post by:
Hi I have an XML documnet and a XSLT document as shown below THe XSLT document brings back a filtered docmument that has the VendorName that starts with a particular sub-string This works as...
2
by: Eric Osman | last post by:
Hi, I'm looking for a javascript function that will convert input such as this: <CLUB Code=" into this: &lt;CLUB Code=&quot;
3
by: NecroJoe | last post by:
I am using PHP to generate a little javascript for one of my pages. In short it allows a user to select a value from a list and pop it into a form field on a seperate page. This works well unless...
5
by: Mateusz Loskot | last post by:
Hi, I'd like to ask how XML parsers should handle attributes which consists of &quot; entity as value. I know XML allows to use both: single and double quotes as attribute value terminator. That's...
3
by: Arpi Jakab | last post by:
I have a main project that depends on projects A and B. The main project's additional include directories list is: ...\ProjectA\Dist\Include ...\ProjectB\Dist\Include Each of the include...
5
by: martin | last post by:
Hi, I would be extremly grateful for some help on producing an xml fragemt. The fragment that I wish to produce should look like this <Addresses> <Address>&qout;Somebody's Name&quot;...
8
by: Ulysse | last post by:
Hello, I need to clean the string like this : string = """ bonne mentalit&eacute; mec!:) \n <br>bon pour info moi je suis un serial posteur arceleur dictateur ^^* \n ...
1
by: manchin2 | last post by:
Hi, Can anybody please provide the information about "&quot" and its use, if possible please provide an example. ...
4
by: fran7 | last post by:
Hi, from help in the javascript forum I found the error in some code but need help. This bit of code works perfectly, trouble is I am writing it to a javascript function so the height needs to be in...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.