Python: Quote String
A string is a sequence of characters.
(in Python 3, it's a sequence of Unicode characters.)
(in Python 2, it's a sequence of bytes (representing ASCII Characters). But if prefixed with
u, then it's a sequence of Unicode characters.)
Quote String by Double Quote
String can be created by double quote.
Literal linebreak in string is not allowed. It's syntax error.
a = "this" print(a)
Quote String by Single Quote
String can also be created by single quote.
'Single quote' and "double quote" delimited strings are effectively the same.
b = 'that' print(b)
String Escape, Backslash
\"for double quote.
\'for single quote.
see Python: String Escape Sequence
r for Raw string (No Backslash Escape)
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
Triple Quote for Multi-Lines String
To quote a string of multiple lines, use triple quotes.
d = """this will be printed in 3 lines""" print(d) # output: # this # will be printed # in 3 lines