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.
Asked
Active
Viewed 249 times
0

martineau
- 119,623
- 25
- 170
- 301

Gamer Crafter
- 35
- 1
- 3
-
What is each sentence of a text? How are they determined? – martineau Jul 27 '21 at 00:08
-
they would be determined by a period. – Gamer Crafter Jul 27 '21 at 00:09
-
1Use something like `for sentence in text.split('.'): print(sentence+'.')` – martineau Jul 27 '21 at 00:12
-
Related: [Pythonic way to create a long multi-line string](https://stackoverflow.com/questions/10660435/pythonic-way-to-create-a-long-multi-line-string) – smci Jul 27 '21 at 00:33
2 Answers
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.

snoopy_doo
- 1
- 2
-
-
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