我想做几条语句,它们提供标准输出,而语句之间没有换行符。
具体来说,假设我有:
for item in range(1,100):
print item
结果是:
1
2
3
4
.
.
.
如何让它看起来像:
1 2 3 4 5 ...
更好的是,是否可以在最后一个数字上打印单个数字,这样屏幕上一次只有一个数字?
最佳答案
将打印项
改为:
打印项目,
在 Python 2.7 中print(item, end="")
在 Python 3 中如果要动态打印数据,请使用以下语法:
print(item, sep=' ', end='', flush=True)
在 Python 3 中https://stackoverflow.com/questions/3249524/