David Labrecque David Labrecque - 8 months ago 34
Python Question

Output "But it didn't sing."

formatter = "%r %r %r %r"
print formatter % (1, 2, 3, 4)
print formatter % (True, False, False, True)
print formatter % (formatter, formatter, formatter, formatter)
print formatter % (
"I had this thing.",
"That you could type up right.",
"But it didn't sing.",
"So I said goodnight."

In this program, there's no mistake, but just a questioning. Notice that the last line of output uses both single-quotes and double-quotes for individual pieces. Why do you think that is? Why they didn't choose to use double quotes around all the strings


It's a duplicate and it's because you're using raw representation of string. So let's see

For this sentence "I had this thing." output will be single or double quoted because there is not single/double qoutes inside string, the only string containing double quoted output will be "But it didn't sing." because it already contains single quotes inside it :)

If you were using %s , you would see only the string without quotes :)