Being wordy

There are several ways to create a string that will span more than one line.

• To write a string that will print exact as you entered it, surround the string with triple-quotes ( or ).

• To write text that will print on several lines, add the linefeed escape code \n where you want a new line to start, like this:

• >>> cheese = "cheeses available:\nsavoyard\nboursin"

• cheeses available:

• To turn two strings on two lines into a single string, surround them with parentheses. We recommend this method for entering long strings because it's easy to read. For example:

• helloworld

• To create a long string, type a backslash character (\) at the end of a line. What you type after you press Return counts as part of the same line.

• >>> longline = "this is a very long line a very long \

• this is a very long line a very long line a very long line

Warning The end-of-line backslash doesn't work if you add spaces after the backslash.

Was this article helpful?

0 0

Post a comment