How to print a new line in Python 3 with a long string?

Dung Do Tien Feb 06 2022 71

Hello Guys, I'm just studying Python one week before. I have a sentence text, it contains some basic information as below:

 print("Good morning everyone, let me introduce a little bit about myself. My name is Nandi, 20 years old, a student at college, female.")

And when running the code above, all text is displayed in a single line but I want to print to newline as below:

Good morning everyone, let me introduce a little bit about myself. 
My name is Nandi, 
20 years old, 
a student at college, 
female.

I try to use many print() methods to do, It worked for me but it was waste of time. 

Do you have any other good solution for me?

Have 2 answer(s) found.
  • T

    Thịnh Nguyễn Văn Feb 06 2022

    You can use /n to break down the newline for you.

    For example:

     print("Good morning everyone, let me introduce a little bit about myself. \nMy name is Nandi, \n20 years old, \na student at college, \nfemale.")

    #Output

    Good morning everyone, let me introduce a little bit about myself. 
    My name is Nandi, 
    20 years old, 
    a student at college, 
    female.
  • i

    imen Feb 06 2022

    You can use linesep property of os package to help create a new line in Python.

    For example:

    import os
    languages = 'Html'+ os.linesep + 'CSS'+ os.linesep + 'Javascript'
    print(languages)

    #output

    Html
    CSS
    Javascript
Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close