Multi-Line printing in Python


We have usually seen the print command in python printing one line of output. But if we have multiple lines to print, then in this approach multiple print commands need to be written. This can be avoided by using another technique involving the three single quotes as seen below.

Example

 Live Demo

print('''
Motivational Quote :\n
Sometimes later becomes never, Do it now.
Great things never come from comfort zones.
The harder you work for something, the greater you'll feel when you achieve it.
''')

Running the above code gives us the following result:

Motivational Quote :

Sometimes later becomes never, Do it now.
Great things never come from comfort zones.
The harder you work for something, the greater you'll feel when you achieve it.


We can use multiline printing to produce nicely formatted text also as seen below.

Example

print('''
===========================================
||                                       ||
|| WORK                                  ||
|| HARD                                  ||
||                                       ||
||                                       ||
||                                       ||
===========================================
''')

Running the above code gives us the following result:

=============================
||                         ||
|| WORK                    ||
|| HARD                    ||
||                         ||
||                         ||
||                         ||
=============================

Updated on: 30-Dec-2019

626 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements