Multi-Line Strings
When you make a Python string with double quotes (" "), you can't use line breaks (spaces in between lines.)
If you try, Python will send you a ParseError, which is a way of saying "Hey! I tried to read – to parse – the words you gave me, but I got confused and couldn't tell what you meant."
If you try, Python will send you a ParseError, which is a way of saying "Hey! I tried to read – to parse – the words you gave me, but I got confused and couldn't tell what you meant."
This is because computers assign special meaning to line breaks. They do this for reasons that used to be important when computers were less powerful.
It's only the line break that Python's allergic to; it's just fine if you've so much text that it spills on to another line:
It's only the line break that Python's allergic to; it's just fine if you've so much text that it spills on to another line:
See? All that overflowing text became a string; it just become one without line breaks
Triple quotes to create strings
How can you make a multi-line string? Surround your words with three sets of double quotes.
Two sets of double quotes?
Surrounding strings with two sets of quotes doesn't do anything. And remember that using one set of double quotes creates a "normal" string.
Challenge!
- Create a string that includes a linebreak
- Create a string that doesn't have a linebreak