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 upper()
Python Recursion
Python type()
Python float()
Python Program to Capitalize the First Character of a String
Python any()
Introduction to Scientific Programming with Python - Joakim Sundnes
Building Machine Learning Systems with Python - Willi Richert & Luis Pedro Coelho
How to get current date and time in Python?
Python Program to Check Leap Year
Python Program to Display the multiplication Table
Python classmethod()
Python List
Python Strings
Python strftime()
Python Machine Learning Cookbook - Practical solutions from preprocessing to Deep Learning - Chris A...
Python super()
Python Program to Extract Extension From the File Name
Deep Learning with Python - Francois Chollet
Python Dictionary pop()
Python Program to Differentiate Between type() and isinstance()
Python Program to Find Factorial of Number Using Recursion
Python Program to Make a Flattened List from Nested List
Python next()
Python Data Types
Deep Learning with Python - Francois Cholletf
Python Dictionary setdefault()
Python Dictionary get()
Python Program to Sort Words in Alphabetic Order
Python String maketrans()
Python RegEx
Python Program to Swap Two Variables