我想知道我们是否可以在 python 中按行打印。
基本上我有一个循环,它可能会运行一百万次,我正在该循环中打印出一些战略计数。所以如果我能像行一样打印,那将非常酷
print x
# currently gives
# 3
# 4
#.. and so on
我看起来像
print x
# 3 4
最佳答案
在 Python2 中:
data = [3, 4]
for x in data:
print x, # notice the comma at the end of the line
或者在 Python3 中:
for x in data:
print(x, end=' ')
打印
3 4
关于python:水平打印而不是当前默认打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8437964/