Single vs Double Quotes in Code: What Every Language Uses, Counted

The short answer: it depends on the language. In Python, JavaScript and TypeScript, single and double quotes make exactly the same string, so pick one and stay consistent. In PHP, double quotes insert variables and escape sequences and single quotes do not. In C, C++, Java and Rust, single quotes hold one character and double quotes hold a string, so swapping them is an error. Backticks (`) make template strings in JavaScript and TypeScript. In the 2,009 literals we counted, PHP used single quotes 86% of the time and Rust used double quotes 95%.
Key Findings
- •
PHP is the single-quote language: 86% of its strings. Only 12 of its 55 double-quoted strings actually insert a variable.
- •
Python leans single (57%), TypeScript leans double (66%), and JavaScript splits 52% double, 43% single and 6% backtick.
- •
Within a snippet, people do not mix. Only 1 of 93 JavaScript snippets and 1 of 87 Python snippets use both single and double quotes.
- •
In C, C++, Java and Rust, all 93 single-quoted literals were one character, exactly as those languages require.
- •
Interpolation is rarer than you would think: 3% to 10% of strings insert a value, even in languages built for it.
Source: TurboType analysis of 1,340 code snippets in nine languages, 2,009 string and character literals, November 2026.
1. Single vs Double Quotes, Language by Language
Whether the choice matters depends entirely on the language. Here is the rule for each of the nine languages we analysed, plus a few you will meet alongside them.
| Language | Single quotes ' | Double quotes " | Does it matter? |
|---|---|---|---|
| Python | A string | The same string | No. Style only |
| JavaScript, TypeScript | A string | The same string | No. Backticks are the different one |
| PHP | A literal string, no variables | A string with variables and escapes | Yes |
| C, C++ | One character, such as 'A' | A string, such as "Ann" | Yes, different types |
| Java | One char | A String | Yes, different types |
| Rust | One char, also lifetimes like 'a | A string slice (&str) | Yes, different types |
| HTML & CSS | Attribute value or CSS string | The same | No. Double is conventional |
| JSON | Not allowed | Required for every string and key | Yes |
| SQL | A string value | A column or table name (standard SQL) | Yes |
| Shell (bash) | Literal text | Text with $variables expanded | Yes |
The JSON row catches people out the most. JavaScript accepts either quote, but JSON, which looks like JavaScript, accepts only double quotes. A config file written with single quotes will fail to parse.
2. What Real Code Uses
We counted every string and character literal in 1,340 snippets from our practice library and recorded the quote it opened with. Triple-quoted Python strings are counted with their quote character.
| Language | Single | Double | Backtick | Literals |
|---|---|---|---|---|
| PHP | 340 (86%) | 55 (14%) | – | 395 |
| Python | 126 (57%) | 94 (43%) | – | 220 |
| JavaScript | 95 (43%) | 115 (52%) | 13 (6%) | 223 |
| TypeScript | 55 (24%) | 152 (66%) | 23 (10%) | 230 |
| C | 36 (28%) | 91 (72%) | – | 127 |
| C++ | 35 (23%) | 114 (77%) | – | 149 |
| Java | 8 (6%) | 116 (94%) | – | 124 |
| Rust | 14 (5%) | 252 (95%) | – | 266 |
| HTML & CSS | 0 | 275 (100%) | – | 275 |
Two patterns stand out. Where the quote is pure style, each language has a lean but no consensus: Python and PHP lean single, TypeScript leans double, JavaScript is close to even. And where the quote has meaning, the numbers just describe the code: Java and Rust programs need far more strings than single characters.
3. PHP: Where the Quote Changes the String
PHP is the language where the choice has real consequences. In double quotes, PHP replaces variables with their values and turns escape sequences into characters: "Hello $name\n" prints the name followed by a new line. In single quotes, 'Hello $name\n' prints exactly those characters, dollar sign and backslash included. Only \' and \\ are escapes inside single quotes.
That is why PHP code leans so heavily on single quotes: 86% of the strings in our PHP snippets. Single quotes say that nothing in this string will change. Of the 55 double-quoted strings, only 16 need them: 12 insert a variable and 4 more use an escape such as \n. The other 39 could be single-quoted with no change in behaviour.
Single quotes also protect strings full of dollar signs. Both single-quoted PHP strings containing $ in our sample are regular expressions, such as '/^[a-zA-Z0-9_-]+$/', where the $ means end of line, not a variable. For longer text PHP has heredoc (<<<HTML), which behaves like double quotes, and nowdoc (<<<'TXT'), which behaves like single quotes. Any speed difference between the two quote styles is negligible in modern PHP; choose by meaning.
4. Python and JavaScript: Pure Style
In Python, JavaScript and TypeScript, "hello" and 'hello' are the same value. The practical rules are short:
- •
Pick one and be consistent. Our snippets already do this: only 1 of 93 JavaScript snippets with strings mixes single and double quotes, 0 of 82 in TypeScript and 1 of 87 in Python.
- •
Switch when the text contains a quote. Write "it's" rather than 'it\'s'. Python's style guide, PEP 8, makes no recommendation between the two and gives exactly this advice: use the other quote to avoid backslashes.
- •
Let the formatter decide. Black, the most common Python formatter, prefers double quotes. In JavaScript, Prettier defaults to double quotes, while the Airbnb style guide and StandardJS use single.
- •
Docstrings use triple double quotes in Python, by convention from PEP 257.
PHP's habits do not carry across. A PHP developer who reaches for single quotes in JavaScript is making a style choice; a JavaScript developer who reaches for double quotes in PHP is quietly turning on variable interpolation.
5. Backticks and Template Literals
In JavaScript and TypeScript, the backtick (`) is a third quote with powers the other two lack. A template literal can insert any expression with ${...} and can run across several lines without escapes: `Hello ${user.name}, you have ${count} messages`.
Our JavaScript and TypeScript snippets use backticks for 6% and 10% of strings, and 35 of the 36 template literals insert a value. People reach for backticks when they need interpolation, not as a default quote. That matches the wider picture: interpolation is a minority of strings in every language we measured.
Python's equivalent is the f-string, f"Hello {name}", used in 20 of 220 Python strings. Outside these languages the backtick has unrelated jobs: inline code in Markdown (and a triple backtick for code blocks), identifier quoting in MySQL, command substitution in older shell scripts, and raw strings in Go. On a US keyboard it is the key to the left of 1, which our number row analysis found is pressed less than once per 1,000 characters.
6. Char vs String in C, C++, Java and Rust
In the C family and Rust, the two quotes create different types. 'A' is a single character; "A" is a string that happens to contain one character. All 93 single-quoted literals in our C, C++, Java and Rust snippets held exactly one character, such as '\n' or 'A', so the code follows the rule perfectly.
- •
C:
'A'is a character constant, and in C its type is actuallyint."A"is an array of two chars, A and a terminating zero. Multi-character constants like'ab'compile but their value is implementation-defined, so avoid them. - •
C++: the same, except
'A'has typechar. - •
Java:
'A'is achar,"A"is aString. Since Java 15, triple double quotes open a multi-line text block. - •
Rust:
'A'is achar, a four-byte Unicode value;"A"is a&str. Rust also uses a lone single quote for lifetimes and loop labels, such as'aand'outer: 74 times in our Rust snippets, more often than it uses character literals.
The classic bug is writing 'hello' in Java or C and getting a compile error, or in C getting a warning and a strange number. If the value is text, it takes double quotes.
7. The Typing Cost of a Quote
On a US keyboard the single quote sits just right of the semicolon, under the right little finger, and the double quote is the same key with Shift. Every double-quoted string costs two extra Shift presses. Across our snippets that is 1,264 double-quoted literals, or 2,528 Shift presses that single quotes would not need.
That is not a reason to switch styles against your formatter, but it does explain why quotes trip people up in typing tests: the pinky does the work, Shift has to come from the left hand, and the closing quote has to match the opening one. Our keystroke analysis shows how much of a programmer's typing already lands on the right pinky.
8. Method and Limits
We analysed 1,340 snippets from TurboType's practice tracks: 150 each in JavaScript, TypeScript, Java, C, C++, PHP, Rust and HTML & CSS, and 140 in Python (ten object-oriented Python snippets were excluded). Comments were removed, then each string or character literal was counted once by its opening quote. Rust lifetimes and loop labels were counted separately, not as literals. Interpolation means a template literal containing ${}, a Python f-string, or a PHP double-quoted string containing a variable.
Limits: each track was written by one team, so its quote style reflects our choices as much as each language's community. Treat the style leanings in Python, JavaScript and TypeScript as one sample, not a census; the rules in the first table are what hold everywhere.
9. Frequently Asked Questions
Should I use single or double quotes in Python?
Either. In Python 'text' and "text" create the same string, and PEP 8 makes no recommendation. Pick one, stay consistent, and switch only when the text contains a quote, as in "it's". If you use the Black formatter, it will convert your strings to double quotes.
Should I use single or double quotes in JavaScript?
Either, as long as you are consistent. Prettier defaults to double quotes; the Airbnb style guide and StandardJS use single quotes. Use backticks when you need to insert a value with ${} or write a string over several lines. JSON, unlike JavaScript, only accepts double quotes.
What is the difference between single and double quotes in PHP?
Double quotes replace variables with their values and process escape sequences such as \n. Single quotes keep the text exactly as written, apart from \' and \\. In our sample 86% of PHP strings used single quotes, and only 12 of 55 double-quoted strings inserted a variable.
Why do C, C++ and Java use single quotes for characters?
Because the quotes create different types. 'A' is a single character, while "A" is a string. Writing 'hello' in Java is a compile error, and in C it gives an implementation-defined number. Rust follows the same rule and also uses a lone single quote for lifetimes such as 'a.
What are backticks used for in programming?
In JavaScript and TypeScript, backticks create template literals, strings that can insert values with ${} and span multiple lines. In Markdown they mark inline code, in MySQL they quote table and column names, in older shell scripts they run a command, and in Go they make raw strings.
Next Steps:
- Set your formatter (Black, Prettier) to one quote style and stop thinking about it.
- Practise quote-heavy code: PHP for single quotes and interpolation, TypeScript for template literals.
- Take the coding typing test and watch for mismatched or unshifted quotes.
