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 String replace()
Python Program to Reverse a Number
Python any()
Python Deep Learning - Valentino Zocca & Gianmario Spacagna & Daniel Slater & Peter Roelants
Python String rpartition()
Python id()
Python String rfind()
Python Program to Sort Words in Alphabetic Order
Python Machine Learning Eqution Reference - Sebastian Raschka
Python Program to Make a Flattened List from Nested List
Python List extend()
Python exec()
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python Program to Generate a Random Number
Python Program to Count the Occurrence of an Item in a List
Deep Learning in Python - LazyProgrammer
Python String maketrans()
Python Namespace and Scope
Python Set copy()
Python Program to Convert Bytes to a String
Python Program to Merge Two Dictionaries
Python Program to Split a List Into Evenly Sized Chunks
Python dir()
Python callable()
Python repr()
Python strftime()
Python Program to Check if a Number is Odd or Even
Python hex()
Python List index()
Python vars()
Python Program to Print the Fibonacci sequence