2024-05-13 03:58:15 发布
网友
我想知道我们是否可以像python中的row-wise一样打印。
基本上,我有一个循环,可能会持续百万次,我在这个循环中打印出一些战略要点。。所以如果我能像行一样打印就太酷了
print x # currently gives # 3 # 4 #.. and so on
我看起来像
print x # 3 4
只需在打印的项目末尾添加一个,。
,
print x, # 3 4
可以在调用print后添加逗号以避免换行:
print 3, print 4, # produces 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
只需在打印的项目末尾添加一个
,
。可以在调用print后添加逗号以避免换行:
在Python2中:
或者在Python3中:
印刷品
相关问题 更多 >
编程相关推荐