How to create strings across multiple lines

Triple quotes

In Python we can create a multi line string by using three quotes.


print """This string has "double quotes" and 'single quotes'.
   You can even do multiple lines."""
print '''This string also has "double" and 'single' quotes.'''

The code above generates the following result.

We can use both single quote and double quote.

The following code uses triple quotes to output ascii art.


print \# ww  w  . j a v  a 2 s  .c o  m
"""
 _____   _     _   _____   _____   
/  _  \ | |   / / |  ___| |  _  \  
| | | | | |  / /  | |__   | |_| |  
| | | | | | / /   |  __|  |  _  /  
| |_| | | |/ /    | |___  | | \ \  
\_____/ |___/     |_____| |_|  \_\
"""

The code above generates the following result.





















Home »
  Python »
    Data Types »




Data Types
String
String Format
Tuple
List
Set
Dictionary