A
A
artur_agishev2021-08-28 17:41:23
Python
artur_agishev, 2021-08-28 17:41:23

How to read text with line breaks and store everything in a variable?

You can, of course, reset the variable with each new line, or add a new readable line to it

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2021-08-28
@fox_12

It's not entirely clear what the problem is:

text = "Строка 1\n"   # считываем строку с переносом
text += "Строка 2\n"  # добавляем еще строку с переносом
text += "Строка 3\n"  # ...
print(text)   # печатаем весь текст с переносами строк
# Строка 1
# Строка 2
# Строка 3

P
PRoGRamm_InG, 2021-08-28
@PRoGRamm_InG

there is a special line break character "\n" for this,
for example:

print("Список продуктов:\nЯблоко\nМорковка\nКартошка")

will issue
Product list:
Apple
Carrot
Potato

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question