This snippet:
formatter = "%r %r %r %r"
print formatter % (
"I had this thing.",
"That you could type up right.",
"But it didn't sing.",
"So I said goodnight."
)
when run, prints this string:
'I had this thing.' 'That you could type up right.' "But it didn't sing." 'So I said goodnight.'
Why did "But it didn't sing."
get put in double quotes when the other three items were in single quotes?
(This code is taken from Learn Python the Hard Way Exercise 8.)
To place quotation marks in a string in your code In Visual C# and Visual C++, insert the escape sequence \" as an embedded quotation mark. For example, to create the preceding string, use the following code. Insert the ASCII or Unicode character for a quotation mark. In Visual Basic, use the ASCII character (34).
Both single (' ') and double (" ") quotes are used to represent a string in Javascript. Choosing a quoting style is up to you and there is no special semantics for one style over the other. Nevertheless, it is important to note that there is no type for a single character in javascript, everything is always a string!
The main difference between double quotes and single quotes is that by using double quotes, you can include variables directly within the string.
Strings in JavaScript are contained within a pair of either single quotation marks '' or double quotation marks "". Both quotes represent Strings but be sure to choose one and STICK WITH IT.
Python is clever; it'll use double quotes for strings that contain single quotes when generating the representation, to minimize escapes:
>>> 'no quotes'
'no quotes'
>>> 'one quote: \''
"one quote: '"
Add a double quote in there as well and it'll revert back to single quotes and escape any single quotes contained:
>>> 'two quotes: \'\"'
'two quotes: \'"'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With