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:
Deep Learning with Python - A Hands-on Introduction - Nikhil Ketkar
Python dict()
Python zip()
Learning scikit-learn Machine Learning in Python - Raul Garreta & Guillermo Moncecchi
Python tuple()
Python len()
Python Program to Check If a List is Empty
Python Program to Sort a Dictionary by Value
Python String maketrans()
Python Program to Concatenate Two Lists
Python time Module
Python callable()
Python Modules
Python compile()
Python Program to Remove Duplicate Element From a List
Python String zfill()
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python Program to Capitalize the First Character of a String
Python Dictionary items()
Python Dictionary update()
Python memoryview()
Python Program to Differentiate Between type() and isinstance()
Python float()
Python Program to Print Hello world!
Python enumerate()
Python complex()
Python Program to Convert Celsius To Fahrenheit
Python RegEx
Python String istitle()
Python Shallow Copy and Deep Copy
Python Program to Find the Factorial of a Number
Deep Learning in Python - LazyProgrammer