如何在Python中添加换行符?

4

我刚刚用Python编写了一个程序,但输出的语句之间太靠近了。那么,如何在两个语句之间添加换行符呢?


你是指脚本中的换行符还是输出结果中的换行符? - Christian Dean
你可以简单地使用 printprint() 来输出一个空行。 - Martin Evans
4个回答

8

您可以打印新行字符:

print('\n'*numlines)

6

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

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

    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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接