There is no semantic difference between ' and " . You can use ' if the string contains " and vice versa, and Python will do the same. If the string contains both, you need to wrest some of them (or use triple quotes, """ or ''' ). (If both ' and " possible, Python and many programmers seem to prefer ' .)
>>> x = "string with ' quote" >>> y = 'string with " quote' >>> z = "string with ' and \" quote" >>> x "string with ' quote" >>> y 'string with " quote' >>> z 'string with \' and " quote'
About print , str and repr : print print the given line without additional quotes, while str will create a line from the given object (in this case the line itself) and repr create a "presentation object" from the object (i.e. a line containing a set of quotes). In a nutshell, the difference between str and repr should be that str easy to understand for the user, and repr easy to understand for Python.
Also, if you type an expression into an interactive shell, Python will automatically repeat the repr result. This can be a bit confusing: in the interactive shell, when you do print(x) , you see str(x) ; when you use str(x) , then you see repr(str(x)) , and when you use repr(x) , you see repr(repr(x)) (thus double quotes).
>>> print("some string") # print string, no result to echo some string >>> str("some string") # create string, echo result 'some string' >>> repr("some string") # create repr string, echo result "'some string'"
source share