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 zip()
Python Program to Display the multiplication Table
Python while Loop
Python Program to Find HCF or GCD
Python String find()
Python Sets
Python Functions
Python open()
Python Program to Check Prime Number
Python max()
Python id()
Python Program to Display Fibonacci Sequence Using Recursion
Python Program to Remove Punctuations From a String
Python Tuple index()
Python List Comprehension
Python Program to Extract Extension From the File Name
Python print()
Python Program to Count the Occurrence of an Item in a List
How to Get Started With Python?
Python map()
Python Program to Find Factorial of Number Using Recursion
Python String rindex()
Python Program to Create a Countdown Timer
Python Machine Learning Third Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Parse a String to a Float or Int
Applied Text Analysis with Python - Benjamin Benfort & Rebecca Bibro & Tony Ojeda
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python Program to Convert Two Lists Into a Dictionary
Python Program to Check If Two Strings are Anagram
Python Program to Reverse a Number
Python setattr()
Python Program to Safely Create a Nested Directory