How to add a line break in python?

帅比萌擦擦* 提交于 2020-05-02 04:37:27

问题


I just made a program in python but the statements are too close to each other in the output. So how can i add a line break between two statements in python.


回答1:


You can print new line characters:

print('\n'*numlines)



回答2:


\n gives you a new line. You can put it anywhere in a string and when printing it you get a new line.

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

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

There are more of this kind, including tabs etc. https://docs.python.org/3/reference/lexical_analysis.html#literals




回答3:


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


来源:https://stackoverflow.com/questions/45377903/how-to-add-a-line-break-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!