Question on Exercise 10: What was that?

Is there a different way to write this? The language seems super confusing. And why does only single quotes appear in the out put?

Study drill code with double/single quotes and %s or %r

print('Didn’t you see {!r}, that’s {!r} '.format(“Michael’s tops”, “crazy”))
print('Didn’t you see {!s}, that’s {!s} '.format(“Michael’s tops”, “crazy”))


Didn’t you see “Michael’s tops”, that’s ‘crazy’
Didn’t you see Michael’s tops, that’s crazy

The command %s uses the string (str) function - i.e., str(), while %r uses the repr function. … In other words, %s knows already that what you are writing is a string, so it does not include quotes around it. But when you create a variable, for example t = " The temperature in Celcius", if you would like to print the variable t and have the output easy to read, with quotes around the phrases, you could use repr(), as it is the literal representation of that variable t, quotes and all.

print (“He said {!r} is -40 degrees.”.format(t)) — quotes
print (“He said {!s} is -40 degrees.”.format(t)) — no quotes

Wellllll, Python has a lot of ways to make a string, so I recommend people learning modern Python become familiar with the others, but just stick to f"" style strings. When Python prints out strings with the !r (or %r) format it doesn’t honor how you wrote it, but rather prints it the way it thinks is best. Since those formats are only really for debugging it kind of doesn’t matter. Python will get it right, even if it’s different from what you wrote.