0

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 ...

the display of console

Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
3Chimenea
  • 3
  • 3

2 Answers2

7

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.

Community
  • 1
  • 1
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • [But what are triple quotes?](https://docs.python.org/3/tutorial/introduction.html#strings) _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._ – erip Mar 18 '16 at 14:59
0

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.

Python 3 implementation:

>>> print("""
...   
... abc
... 
... ggg
... 
... """)


abc

ggg


>>> 

Python 2.7 implementation:

>>> print r"""
... blah
... black sheep
... """

black sheep
blah
benSooraj
  • 447
  • 5
  • 18
snakecharmerb
  • 47,570
  • 11
  • 100
  • 153