Multiline Strings in Python

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.

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.


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.

3 Single Quote
3 Single Quote

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 \n  which means new line.



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

Multiline Strings in Python Infographic

Multiline Strings in Python Infographic
Multiline Strings in Python Infographic


LEARN MORE  How To Prevent SQL Injection in Php Applications?

Leave a Comment