How to print multiple lines in Python

Implementation

Code 1

To print a single line, we cover our string with single/double quotes and pass it to the print() function:

print(" Hello World ")
#or
print(' Hello Again ')

Code 2

Similarly, using triple quotes enables us to print multiple lines in one statement:

print('''
|==[[[[[]]]]]==||==[[[[[]]]]]==|
|==[[[[[]]]]]==||==[[[[[]]]]]==|
|==[[[[[]]]]]==||==[[[[[]]]]]==|
|==[[[[[]]]]]==||==[[[[[]]]]]==|
|==[[[[[]]]]]==||==[[[[[]]]]]==|
|==[[[[[]]]]]==||==[[[[[]]]]]==|
''')

Note: the triple quote must be made by three single quotes rather than a single quote and a double quote.

Copyright ©2024 Educative, Inc. All rights reserved