Last Updated : 23 Jul, 2025
A sequence of characters is called a string. In Python, a string is a derived immutable data type—once defined, it cannot be altered. To change the strings, we can utilize Python functions like split, join, and replace.
Python has multiple methods for defining strings. Single quotations (''), double quotes (" "), and triple quotes (''' ''') are all acceptable.
Python Multiline StringThere are several approaches to implementing the multiline string in Python. To define multi-line strings, we can use backlash, brackets, and triple quotes. To better understand the Python multiline string, below are the following approaches:
Using the triple quotes style is one of the easiest and most common ways to split a large string into a multiline Python string. Triple quotes (''' or """) can be used to create a multiline string. It allows you to format text over many lines and include line breaks. Put two triple quotes around the multiline Python string, one at the start and one at the end, to define it.
Python
multiline_string = '''This is a
multiline
string.'''
print(multiline_string)
This is a multiline string.Create a Python Multiline String Using parentheses and single/double quotes
A different method to define a multiline string in Python is to include its components in brackets. Both single quotes ('') and double quotations ("") are acceptable, as was previously shown. To learn how to use them, look at the examples provided below.
Python
colors = ("multi-line string"
"red \n"
"blue \n"
"green \n"
"yellow \n"
)
print(colors)
multi-line stringred blue green yellowPython Multiline String Using Backslash
In Python, we can divide a string into many lines by using backslashes. The backslash character in Python serves as a line continuation character. It is used to combine text that consists of individual lines.
Python
x = "multiline String" \
"I love Python" \
"Python Langauge"
print(x)
multiline StringI love PythonPython LangaugeCreate a Python Multiline String Using Brackets
When there is no newline in the string, there is another method for declaring a multiline string in Python that involves using brackets. Let's examine it in the following example:
Python
x = "multiline String" \
"I love Python" \
"Python Langauge"
print(x)
multiline StringI love PythonPython LangaugePython Multiline String Creation Using join()
In this option, we break up multiple strings for printing multiline strings using Python's string join() function. Because it would be difficult to skip a space when using brackets or backslashes in a very lengthy string, the two alternatives above included a condition to check for spaces when we use them. However, this issue may be fixed by utilizing the string join() method. Below is an example to help you understand it.
Python
x = ' '.join(("multiline String ",
"Python Language",
"Welcome to GFG"))
print(x)
multiline String Python Language Welcome to GFGMultiline String in Python Using string.format()
In this option, we can use variables to format a string by using string.format(). This can be helpful for writing scripts, code, or other formatted text. Below is an example to help you understand it.
Python
car = "Ferrari"
price = 250000
x = "Hello, The price of {} is {}".format(car, price)
print(x)
Hello, The price of Ferrari is 250000Multiline String Creation Using % in Python
In this option, Python's % operator is used to format strings. It returns a formatted string after receiving as inputs a tuple of values and a format string. The values in the tuple are represented as substituted in the format string.
Python
name = "Rahul"
points = 100
x = "Hello, %s! You have %d coins." % (name, points)
print(x)
Hello, Rahul! You have 100 coins.
The % operator can also be used to format numbers, dates, and times.
Python
marks = 49.99
total_marks = "%0.2f" % marks
print(total_marks)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4