Table of Contents
In this example, you will learn to create a long multiline string.
To understand this example, you should have the knowledge of the following Python programming topics:
1. Example 1: Using triple quotes
my_string = '''The only way to learn to program is by writing code.''' print(my_string)
Output
The only way to learn to program is by writing code.
You can use '''(multiline string)''' or """(multiline string)""" to print a multiline string as shown above.
2. Example 2: Using parentheses and a single/double quotes
my_string = ("The only way to \n"
"learn to program is \n"
"by writing code.")
print(my_string)
Output
The only way to learn to program is by writing code.
If you use (" ") syntax, you need to specify the newlines explicitly using \n.
3. Example 3: Using \
my_string = "The only way to \n" \
"learn to program is \n" \
"by writing code."
print(my_string)
Output
The only way to learn to program is by writing code.
You can use \ as in the above example code to write a multiline string.
Related posts:
Python String find()
Python Program to Display Calendar
Python Program to Iterate Through Two Lists in Parallel
Python String isspace()
Python len()
Python Program to Make a Simple Calculator
Python Program to Print Output Without a Newline
Python Shallow Copy and Deep Copy
Python Program to Find the Sum of Natural Numbers
Python Program Read a File Line by Line Into a List
Python Generators
Python String endswith()
Python Program to Display Powers of 2 Using Anonymous Function
Python hex()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python Machine Learning Eqution Reference - Sebastian Raschka
Python reversed()
Python any()
Python Program to Transpose a Matrix
Python Set difference_update()
Python help()
Python Program to Convert Two Lists Into a Dictionary
Python Program to Merge Mails
Natural Language Processing with Python - Steven Bird & Ewan Klein & Edward Loper
Python Program to Illustrate Different Set Operations
Python String lstrip()
Python Program to Extract Extension From the File Name
Python if...else Statement
Python oct()
Python String strip()
Python Program to Shuffle Deck of Cards
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...