在Python中添加CMD换行符
我该如何在Python中添加CMD换行符呢?我试过以下方法,但结果还是显示成了一段话。
print "Welcome to xbrEra's first application";
print
print " using Python 2.7.1. I hope you enjoy";
print
print "-------------------------------------";
print
3 个回答
2
如果你想要对一段普通文本的格式进行更好的控制,可以使用三重引号字符串。
print """
Welcome to xbrEra's first application
using Python 2.7.1. I hope you enjoy
-------------------------------------
"""
2
在Python中,使用print语句时,它会自动在输出的内容后面加一个换行符(这个换行符可能是'\r\n'或者'\n',具体取决于你的操作系统)。如果你不想让它自动加换行,可以在print语句的结尾加一个逗号。比如说,你可以写 print "hello,world",
这样就不会换行了。此外,你也可以在字符串中手动添加换行符来达到同样的效果。
3
根据你使用的操作系统:
print "\n"
或者
print "\r\n"