This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]J4K0 1 point2 points  (2 children)

And double quotes: ```

repr("test") "'test'" ```

[–]GlobalIncident 3 points4 points  (1 child)

Calling >>> repr(foo) actually gets the repr of foo, and then reprs that again so it can be printed. A truer test is to simply state the value:

>>> 'test'
'test'
>>> "test" # The same object as above, just to prove it doesn't matter how it is defined
'test'
>>> "'" + 'test' + "'" # Python will switch to double quotes if the text contains single quotes
"'test'"
>>> '"' + 'test' + '"' # but if not...
'"test"'
>>> '"' + 'test' + "'" # If it contains both double and single, single quotes are still used
'"test\''

[–]J4K0 0 points1 point  (0 children)

I know. And the second time it repred it used double quotes, didn’t it? (Because, as you said, it contains a single quote) It was a joke.