Why does print r"""
return the string ...
and doesn't exit?
When I press Enter, the console displays a new row preceded by the string ...
Why does print r"""
return the string ...
and doesn't exit?
When I press Enter, the console displays a new row preceded by the string ...
Because the three quotes are seen as the beginning of a triple-quoted string. It is waiting for you to type another set of triple quotes.
>>> print r"""
... blah
... """
blah
>>>
For more information see:
"""
(The second link is to 2.7 docs since your example used python 2.x syntax).
A direct quote from the python documentation:
String literals can span multiple lines. One way is using triple-quotes: """...""" or '''...'''. End of lines are automatically included in the string, but it’s possible to prevent this by adding a \ at the end of the line.
print r"""
starts a multi-line string.
Because the string hasn't been terminated with another """
the interpreter keeps printing ...
, waiting for you to type the next line or match the opening quotes with a closing one. So, if you type """
again the standard interpreter prompt >>>
will reappear or resume.
>>> print("""
...
... abc
...
... ggg
...
... """)
abc
ggg
>>>
>>> print r"""
... blah
... black sheep
... """
black sheep
blah