Write a Python Program to Create a Long Multiline String

Python is a popular programming language used for a variety of applications.

One of the most common tasks in Python programming is creating long multiline strings.

In this tutorial, we will show you how to create a long multiline string in Python.


A string is a sequence of characters enclosed in quotes.

In Python, you can create multiline strings by enclosing the text in triple quotes (”’ or “””).

This allows you to create strings that span multiple lines.

Let’s take a look at an example:

long_string = '''This is a long
multiline string
that spans multiple lines.'''

In this example, we have created a long multiline string that spans three lines.

The string is enclosed in triple quotes (”’) and contains line breaks (\n) to separate the lines.

You can also create a multiline string using the concatenation operator (+).

For example:

long_string = 'This is a long ' + \
              'multiline string ' + \
              'that spans multiple lines.'

In this example, we have created the same long multiline string using the concatenation operator.

We have used the backslash () to indicate that the string continues on the next line.

You can also use the join() method to concatenate multiple strings into a single multiline string.

For example:

strings = ['This is a long', 'multiline string', 'that spans multiple lines.']
long_string = '\n'.join(strings)

In this example, we have created a list of strings and used the join() method to concatenate them into a single multiline string.

We have used the ‘\n’ character to separate the lines.


In conclusion, there are several ways to create long multiline strings in Python.

You can use triple quotes, the concatenation operator, or the join() method to create strings that span multiple lines.

By using these techniques, you can create readable and maintainable code in your Python programs.