我刚刚用Python编写了一个程序,但输出的语句之间太靠近了。那么,如何在两个语句之间添加换行符呢?
您可以打印新行字符:
print('\n'*numlines)
\n
表示换行符,可以在字符串中的任何位置使用,在打印时会换行。
In [1]: print('ab')
ab
In [2]: print('a\nb')
a
b
还有更多这样的内容,包括标签等。 https://docs.python.org/zh-cn/3/reference/lexical_analysis.html#literals
print(output1 + "\n")
print(output2)
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
print
或print()
来输出一个空行。 - Martin Evans