Чтобы написать разрыв строки в Python, вы можете использовать различные методы. Вот несколько вариантов:
-
Метод 1. Использование символа новой строки «\n»:
print("This is the first line.\nThis is the second line.") -
Метод 2. Использование функции print с параметром sep:
print("This is the first line.", "This is the second line.", sep="\n") -
Метод 3. Использование тройных кавычек для многострочных строк:
print('''This is the first line. This is the second line.''') -
Метод 4. Использование метода записи при обработке файлов:
with open("output.txt", "w") as file: file.write("This is the first line.\n") file.write("This is the second line.\n") -
Метод 5. Использование f-строк (форматированных строк):
line1 = "This is the first line." line2 = "This is the second line." output = f"{line1}\n{line2}" print(output)