0

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.

martineau
  • 119,623
  • 25
  • 170
  • 301
Gamer Crafter
  • 35
  • 1
  • 3

2 Answers2

2

Try this:

s = 'this is. the text. that you. want to separate'.replace('.','\n')
print(s)
smci
  • 32,567
  • 20
  • 113
  • 146
j__carlson
  • 1,346
  • 3
  • 12
  • 20
0

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.

  • What if the text is in a variable? Or read from a file? – Tomerikoo Jun 29 '22 at 08:39
  • What? What do you mean? I don't see how your answer answers the question. You propose to manually write the whole string. IU doubt that what the question is asking for. Assuming you have a string as `"hello. this is. a text."` every sentence (separated by a period) should be printed on a separate line... – Tomerikoo Jun 29 '22 at 08:49