To make a string that prints exactly as you type it, use triple quotes, either single ( ) or double ( ). Python prints the string with line breaks and spaces exactly as you enter them, as shown:

... spam spam spam spam spam

>>> print spam spam spam spam spam spam and spam

Triple quotes are most commonly used to create docstrings. A docstring is a short description of a code block, such as a function. Python's help function automatically formats and returns the text of the docstring when you ask for help on the code block. For more about docstrings, see Chapter 11.

Tip Triple quotes are also useful for surrounding text that has both single and double quotation marks.

Was this article helpful?

0 0

Post a comment