简体   繁体   中英

Is it possible to write each sentence of a text of a different line?

So I was wondering if it was possible to have the program write each line of say, a story on a different line, without you having to type each of the sentences in a separate print function. It's silly but also a serious question.

Try this:

s = 'this is. the text. that you. want to separate'.replace('.','\n')
print(s)

Yes! To print text spanning different lines just enclose the text within three single quotation marks.

print('''line 1
         line 2
         line 3''')

sample_text = '''This is a text.
It spans across multiple lines.
I can put this within triple quotes'''

OR

sample_text = "This is a text.\n It spans across multiple lines.\nI can use escape sequences."

Both of the above will give the same output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM