close

How to print multiple lines of text with Python

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn aboutn How to print multiple lines of text with Python in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to print multiple lines of text with Python?

  1. How to print multiple lines of text with Python?

    As far as I know, there are three different ways.
    Use os.linesep in your print:
    print(f"first line{os.linesep}Second line")
    Use sep=os.linesep in print:
    print("first line", "second line", sep=os.linesep)

  2. print multiple lines of text with Python

    As far as I know, there are three different ways.
    Use os.linesep in your print:
    print(f"first line{os.linesep}Second line")
    Use sep=os.linesep in print:
    print("first line", "second line", sep=os.linesep)

Method 1

You can use triple quotes (single ‘ or double “):

a = """
text
text
text
"""

print(a)

Method 2

As far as I know, there are three different ways.

Use os.linesep in your print:

print(f"first line{os.linesep}Second line")

Use sep=os.linesep in print:

print("first line", "second line", sep=os.linesep)

Use triple quotes and a multiline string:

print("""
Line1
Line2
""")

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read