June 2017
Beginner
352 pages
8h 39m
English
Literal strings in Python are delimited by quotes:
>>> 'This is a string'
You can use single quotation marks, as we have above. Or you can use double quotation marks, as shown below:
>>> "This is also a string"
You must, however, be consistent. For example, you can't use a double quotation mark paired with a single quotation mark:
>>> "inconsistent' File "<stdin>", line 1 "inconsistent' ^SyntaxError: EOL while scanning string literal
Supporting both quoting styles allows you to easily incorporate the other quote character into the literal string without resorting to ugly escape character gymnastics:
>>> "It's a good thing.""It's a good thing.">>> '"Yes!", he said, "I agree!"''"Yes!", he said, "I agree!"'
Notice that ...
Read now
Unlock full access