Python Program to Create a Long Multiline String – 2023

Hey guys, in this blog we will see a Python Program to Create a Long Multiline String.

Example 1: Using triple quotes

my_string = '''I love the blogs from Machine Learning Projects.
They are well written with proper explanations,
that even a beginner can understand.'''

print(my_string)

Output

I love the blogs from Machine Learning Projects.
They are well written with proper explanations,
that even a beginner can understand.
  • Using triple quotes (”’) we can create a long multiline string.

Example 2: Using parenthesis and single/double quotes

my_string = ("I love the blogs from Machine Learning Projects. \n"
        	"They are well written with proper explanations, \n"
        	"that even a beginner can understand.")

print(my_string)

Output

I love the blogs from Machine Learning Projects.
They are well written with proper explanations,
that even a beginner can understand.
  • We can create a long multiline string using parenthesis and new line character(‘\n’) also in an above-shown way.

Example 3: Using \

my_string = "I love the blogs from Machine Learning Projects. \n" \
        	"They are well written with proper explanations, \n" \
        	"that even a beginner can understand."

print(my_string)

Output

I love the blogs from Machine Learning Projects.
They are well written with proper explanations,
that even a beginner can understand.
  • It is the same way as above except for the fact here we are not using parenthesis.
  • Here we are using the ‘\’ character which shows the continuation of a string in multiple lines.

Check out our other python programming examples

Abhishek Sharma
Abhishek Sharma

Started my Data Science journey in my 2nd year of college and since then continuously into it because of the magical powers of ML and continuously doing projects in almost every domain of AI like ML, DL, CV, NLP.

Articles: 521

Leave a Reply

Your email address will not be published. Required fields are marked *