如何用python打印空行?
我还没有找到这方面的任何消息。如何用python打印空行?,python,Python,我还没有找到这方面的任何消息。 我想知道如何使用可以打印出20行空白的功能(例如,clear\u screen)。 我的程序的最后一行应该是调用清除屏幕 我的代码的开头是: def new_line(): print def three_lines(): new_line() new_line() new_line() def nine_lines(): three_lines() three_lines() three_lines() p
我想知道如何使用可以打印出20行空白的功能(例如,
clear\u screen
)。我的程序的最后一行应该是调用
清除屏幕
我的代码的开头是:
def new_line():
print
def three_lines():
new_line()
new_line()
new_line()
def nine_lines():
three_lines()
three_lines()
three_lines()
print " "
nine_lines()
print " "
打印功能可以工作,但不能与clear\u screen()
一起工作,这就是我需要工作的地方。如果有人能帮助我或有任何建议,那就太好了,谢谢。我认为没有一种跨平台的方式。因此,与其依赖于
os.*
,不如采用以下方法
print("\n"*20)
我认为没有一种跨平台的方式。因此,与其依赖于
os.*
,不如采用以下方法
print("\n"*20)
您的
清除屏幕可以
基于操作系统的
def clear_screen():
import os
os.system( [ 'clear', 'cls' ][ os.name == 'nt' ] )
适用于unix和Windows。
资料来源:
基于换行符的
def clear_screen():
print '\n'*19 # print creates it's own newline
根据您的评论,您的代码似乎是
def new_line():
print
def three_lines():
new_line()
new_line()
new_line()
def nine_lines():
three_lines()
three_lines()
three_lines()
print " "
nine_lines()
print " "
它将起作用,而且确实如此,
但是如果打印'\n'*8
也能做到这一点,你为什么想要这么长的代码
速度测试
即使你没有速度限制,这里有一些100次跑步的速度统计
os.system function took 2.49699997902 seconds.
'\n' function took 0.0160000324249 seconds.
Your function took 0.0929999351501 seconds.
您的清除屏幕可以
基于操作系统的
def clear_screen():
import os
os.system( [ 'clear', 'cls' ][ os.name == 'nt' ] )
适用于unix和Windows。
资料来源:
基于换行符的
def clear_screen():
print '\n'*19 # print creates it's own newline
根据您的评论,您的代码似乎是
def new_line():
print
def three_lines():
new_line()
new_line()
new_line()
def nine_lines():
three_lines()
three_lines()
three_lines()
print " "
nine_lines()
print " "
它将起作用,而且确实如此,
但是如果打印'\n'*8
也能做到这一点,你为什么想要这么长的代码
速度测试
即使你没有速度限制,这里有一些100次跑步的速度统计
os.system function took 2.49699997902 seconds.
'\n' function took 0.0160000324249 seconds.
Your function took 0.0929999351501 seconds.
使用诅咒——Python librarycheck@drewk:的一部分在Windows上不可用。@TimPietzcker:then@TimPietzcker:那么好——解决方案是抵制MS,直到Windows是POSIX>:-)使用诅咒——Python库的一部分检查@drewk:在Windows上不可用。@TimPietzcker:then@TimPietzcker:OK then--解决方案是抵制MS,直到Windows关闭POSIX>:-)你知道你的第二个“这里”指向同一问题的另一个答案,对吗?;):D@Cthulhu是的,事实上我本来想发布的,但是你就在我之前发布了,所以我想我会把它链接到你的。你知道你的第二个“这里”指向同一个问题的另一个答案吗?;):D@Cthulhu是的,事实上我本来想发布的,但是你就在我之前发布了,所以我想我会把它链接到你的。谢谢!我的代码的开头是def new_line():print def three_line():new_line()new_line()def nine_line():three_line()three_line()print“nine_line()print”和print函数wors,但不使用def clear_screen():这就是我需要解决的问题?@user2130691请将代码添加到问题中。没有缩进,我无法跟上。@Cthulhu我在更新中发布了他的代码……谢谢!我的代码的开头是def new_line():print def three_line():new_line()new_line()def nine_line():three_line()three_line()print“nine_line()print”和print函数wors,但不使用def clear_screen():这就是我需要解决的问题?@user2130691请将代码添加到问题中。没有缩进,我无法跟上。@Cthulhu我在一次更新中发布了他的代码。。。