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…