Python Program to Create a Long Multiline String
A long multiline string is a string that spans across multiple lines. It is created by enclosing the string in triple quotes (either single quotes or double quotes) at the beginning and end of the string.
Using triple quotes allows for a string to contain line breaks and other special characters without having to escape them with backslashes. This makes it easier to create and read strings that contain multiple lines of text.
Python Code :
The below Python program creates a long multiline string:
# Use triple quotes to create a multiline string
long_string = """This is a long
multiline string
that spans multiple
lines.
"""
# Print the string to confirm that it was created correctly
print(long_string)
In this program, we use triple quotes (""") to create a multiline string that spans multiple lines. We assign the string to the variable long_string.
Inside the triple quotes, we include the text that we want to appear in the string, with each line separated by a newline character (\n).
Finally, we print the string to confirm that it was created correctly. Note that you can include any text you like in the string, including variables, expressions, and formatting codes using f-strings or the format() method.