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 48 times
1
martineau
- 112,593
- 23
- 157
- 280
Gamer Crafter
- 17
- 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
1 Answers
0
Try this:
s = 'this is. the text. that you. want to separate'.replace('.','\n')
print(s)
smci
- 29,564
- 18
- 109
- 144
j__carlson
- 1,272
- 3
- 10
- 18
-
@DYZ: ok I should have said [`str` is both the name of a builtin type, and conversion function](https://docs.python.org/3/library/stdtypes.html?highlight=str#str). Same point. – smci Jul 27 '21 at 00:44