Strings

To create string literals, enclose them in single, double, or triple quotes as follows:

a = 'Hello World' 
b = "Python is groovy" 
c = """What is footnote 5?""" 

The same type of quote used to start a string must be used to terminate it. Triple-quoted strings capture all the text that appears prior to the terminating triple quote, as opposed to single- and double-quoted strings, which must be specified on one logical line. Triple quotes can be done with either single quotes (as in the following example) or double quotes (as in the above example). Triple-quoted strings are useful when the contents of a string literal span multiple lines of text such as the following:

 print '''Content-type: text/html <h1> Hello World </h1> Click <a href="http://www.python.org">here</a>. ...

Get Python Essential Reference, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.