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 Program to Reverse a Number
Python list()
Python Program to Differentiate Between type() and isinstance()
Python String count()
Python Dictionary values()
Python Program to Calculate the Area of a Triangle
Python divmod()
Python input()
Python Artificial Intelligence Project for Beginners - Joshua Eckroth
Python Program to Get Line Count of a File
Python Functions
Python str()
Python Program to Create Pyramid Patterns
Python Set remove()
Python String isdigit()
Python Recursion
Python abs()
Python print()
Python List count()
Python Program to Print the Fibonacci sequence
Python Program to Compute all the Permutation of the String
Python String endswith()
Python iter()
Python Numbers, Type Conversion and Mathematics
Python String rjust()
Python Namespace and Scope
Python Program to Generate a Random Number
Python Program to Check If a String Is a Number (Float)
Python List pop()
Python Program to Find the Factors of a Number
Python Global Keyword
Python Variables, Constants and Literals