Strings are enclosed using single quote or double quote. example
a = "this " b = 'and that' print a, b
You can use
\n for linebreak, and
\t for tab, etc.
Complete list of escape sequences: 2. Lexical analysis — Python v2.7.6 documentation#string-literals
a = "this\nthat\n" # use \n for line-break b = 'more\nthings' # single quote works too print a, b
You can add
r in front of the quote symbol. This way, backslash characters will be interpreted as is, not as escapes. (“r” for “raw”)
c = r"this\n and that" print c # prints a single line
To quote a string of multiple lines, use triple quotes. Example:
d = """this will be printed in 3 lines""" print d
Python string quote summary:
rin front of your quoting char (⁖
r"hot") if you want backslash to be literal.
'''single'''quote or triple
"""double"""quote. You can still prefix
u"greek α". But you also need to add a declaration
#-*- coding: utf-8 -*-. The “r” and “u” can be combined, like this:
ur"I ♥ Python"See: Python Unicode Tutorial 🐍.