In this article we will discuss different ways to create long multi line string in python.

Using triple quotes to create string of multiple lines

We can wrap the multi line string in triple quotes i.e. either <> and assign it to a string variable. It will be stored in same multi line format.
Checkout this example,

Output:

Create single line string object from multiple lines

Using Brackets:

If we want to create a string object from long multiple lines but all should be stored in a single line then we should use brackets i.e.

Output:

Here all the given multiple lines are merged to a single line and assigned back to string variable.

Using Escape symbol:

We can create a single line string object from long multiple lines using escape character too i.e.

Output:

Here all the given multiple lines are merged to a single line and assigned back to string variable.

Using join() :

We can create a single line string object by joining multiple lines too i.e.

Output:

Here all the given multiple lines are merged to a single line and assigned back to string variable.

Complete example is as follows:

Output:

 

If you didn't find what you were looking, then do suggest us in the comments below. We will be more than happy to add that.

Do Subscribe with us for more Articles / Tutorials like this,