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 Get the Full Path of the Current Working Directory
Python Inheritance
Machine Learning Mastery with Python - Understand your data, create accurate models and work project...
Python Program to Convert String to Datetime
Python Program to Convert Two Lists Into a Dictionary
Python Set issubset()
Python Program to Print Colored Text to the Terminal
Python Program to Find ASCII Value of Character
Python sleep()
Python super()
Python Program to Parse a String to a Float or Int
Python Machine Learning Second Edition - Sebastian Raschka & Vahid Mirjalili
Python Program to Count the Number of Each Vowel
Python id()
Python round()
Python String center()
Python all()
Python Program to Find Factorial of Number Using Recursion
Python Set copy()
Python Program to Split a List Into Evenly Sized Chunks
Python Program to Iterate Through Two Lists in Parallel
Python String isspace()
Python reversed()
Python Program to Represent enum
Python classmethod()
Python staticmethod()
Python @property decorator
Python next()
Python repr()
Python Set symmetric_difference()
Python Type Conversion and Type Casting
Python isinstance()