且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从文本文件读取和打印时如何防止程序添加不需要的空行-Python3

更新时间:2022-06-15 09:52:26

print 函数中使用 end 参数,就像这样

Use end parameter in print function, like this

print(line_number, a_line, end="")

print 的默认参数列表函数如下所示,

The default list of parameters to print function looks like this,

print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)

由于 end 具有 \ n ,因此每次调用 print 后都会插入新行.

Since end has \n, a new line will be inserted after every print call.