December 2017
Beginner
412 pages
10h 8m
English
If you create a string using single or double quotes, the whole string must fit onto a single line.
Here’s what happens when you try to stretch a string across multiple lines:
| | >>> 'one |
| | File "<stdin>", line 1 |
| | 'one |
| | ^ |
| | SyntaxError: EOL while scanning string literal |
As we saw in Creating Strings of Characters, EOL stands for “end of line”. So in this error report, Python is saying that it reached the end of the line before it found the end of the string.
To span multiple lines, put three single quotes or three double quotes around the string instead of one. The string can then span as many lines as you want:
| | >>> '''one |
| | ... two |
| | ... three''' |
| | 'one\ntwo\nthree' |
Notice that ...
Read now
Unlock full access