Python supports different type and format strings. In this tutorial we will simply look multi line strings. We have following code and want to type it in single expression in multi line.

Joining Line By Line

The most basic and simplest form is adding string lines step by step like below. We will use . in order to add strings together which will create a multi line string which is stored in a variable named $html in this example.

html="<html><body>"; html.="</body></html> echo $html

Double Quote

We can use double quote by wrapping multiple lines. This will legal for python programming. And we can end the string whenever we want like below.

html="<html><body> </body></html>"

3 Single Quote

By default single quote is used to express single line strings. But 3 single quote can be used to express multiline strings in Python programming language.

html='''<html><body><br> </body></html>'''

Single Line

Basic for is single line string. We can use single line Python strings like below where a double quote with a single line stored in a variable which is html in this example. We will use

which means new line.

html="<html><body>

<br></body></html>"

EOF

EOF is special keyword used to specify multi line strings. The start of the multi line string is marked with <<< EOF and then the string will be given. We also need to specify the end of the string with EOF too like below.

html= <<< EOF <html><body> </body></html> EOF

Multiline Strings in Python Infographic