DEV Community

Cover image for Quotation Marks, Single or Double?
Anita Olsen*°•.¸☆
Anita Olsen*°•.¸☆

Posted on

Quotation Marks, Single or Double?

Which type of quotation marks are the best or the right ones to use, the single or the double ones? I tend to use double quotation marks because I find those easier to find and use on my Scandinavian keyboard (they do not share the same key) but I would love to hear what you guys suggest.

For example in Python:
print("Hello world!")
print('Hello world!')

Quotation marks, single or double? Which ones do you use and why?

Top comments (10)

Collapse
 
moopet profile image
Ben Sinclair

Single- and double quotes behave differently depending on the language you're using. For example, in PHP, variables are interpreted inside double-quotes:


$name = "Ben";

echo "Hello $name";
// Hello Ben

echo 'Hello $name';
// Hello $name
Enter fullscreen mode Exit fullscreen mode

So single-quotes are I suppose infinitesimally faster. Don't worry about that.
For general text, use double-quotes, because you're way more likely to use a single-quote as a substitute for an apostrophe in blocks of text than you are to include a quotation.

Collapse
 
pauljlucas profile image
Info Comment hidden by post author - thread only accessible via permalink
Paul J. Lucas

Single and double quotes mean totally different things in languages like C and C++.

The OP's question is ill-formed.

Collapse
 
lexlohr profile image
Info Comment hidden by post author - thread only accessible via permalink
Alex Lohr

Just use the default settings of Prettier and stop overthinking things.

Collapse
 
ooosys profile image
oOosys • Edited

For example at bash command line prompt:

~ $ echo '$0.00€  $$'  # gives: $0.00€  $$
~ $ echo "$0.00€  $$"  # gives: bash.00€  13934
Enter fullscreen mode Exit fullscreen mode

you will get significantly different output as the kind of quotation really matters.

In other words: Use the quotation marks appropriate for the specific use case and refrain from the idea that there are "best or the right ones to use".

In Python I often prefer to use in for example f-strings the triple quotation marks as they allow me to use any single other ones in the string's text. SciTE as text editor has Python highlighting supporting different styles for all the different Python quotation mark variants you can then use to "colorize" your coding:

SciTE multicoloredSyntaxDemo

Happy coding in New Year 2024 to you!

P.S. in the oOo way of approaching programming any usual ASCII Unicode characters will be considered to be a comment if not used within special marked blocks. so there will be no special meaning for quotation marks and no reason to prefer one over the other. And I you want the quotes to be less disruptive use single quotation marks.

Collapse
 
montyharper profile image
Monty Harper

Single quotes (in English) are typically used for a quote within a quote. For example: I told my friend, "According to California State University San Marcos (my online source), 'Single Quotation Marks are used to indicate dialogue within another quotation.'"

Collapse
 
ranjancse profile image
Ranjan Dailata • Edited

Double quotes are perfectly fine, I do use them from time to time on my own blog posts. Any quotes of interest can be technically represented using double quotes. However, with the Markdown format, one should use ">" symbol as shown below.

This is a quote

Collapse
 
arindam-sahoo profile image
Arindam Sahoo • Edited

As long as an English Teacher is not having a look at your code, it's fine. Jk, You can use any of them if you are using programming languages like Python, JS, etc. What I did when I shifted from Java, I used single quotations for characters and double quotations for strings 'coz of my habit. And, now I use the one that does not let me overthink.

Collapse
 
coderhgw profile image
coderhgw

I perfer single

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
decker67 profile image
decker

Single

Some comments have been hidden by the post's author - find out more