如何在 python 中添加换行符?

How to add a line break in python?

我刚刚在 python 中编写了一个程序,但是输出中的语句彼此太接近了。那么如何在 python.

中的两个语句之间添加换行符

\n 给你换行。您可以将它放在字符串中的任何位置,打印时会换行。

In [1]: print('ab')
ab

In [2]: print('a\nb')
a
b

还有更多这种类型,包括标签等。 https://docs.python.org/3/reference/lexical_analysis.html#literals

print(output1 + "\n")
print(output2)

可以打印换行符:

print('\n'*numlines)

打印带有换行符的语句列表:

    list=['statement one','statement two', 'statement three']
    list_element_on_separate_line = '\n'.join(list)
    print(list_element_on_separate_line)`
>>>
statement one
statement two
statement three