我想把循环输出打印到同一行的屏幕上。
对于Python3.x,如何以最简单的方式实现这一点
我知道Python2.7在行尾使用逗号(即print I)提出了这个问题,但我找不到Python3.x的解决方案
i = 0
while i <10:
i += 1
## print (i) # python 2.7 would be print i,
print (i) # python 2.7 would be 'print i,'
屏幕输出。
1
2
3
4
5
6
7
8
9
10
我想打印的是:
12345678910
新读者也可以访问此链接http://docs.python.org/release/3.0.1/whatsnew/3.0.html
类似的建议,您可以:
*对于python 2.x*
使用尾随逗号以避免换行。
上述代码片段的输出将是
*对于python 3.x*
上述代码片段的输出将是(当
<separator> = " "
)时来自
help(print)
:您可以使用
end
关键字:请注意,您必须自己
print()
最后一行。顺便说一句,在Python 2中,你不会得到带有逗号的“12345678910”,而是得到1 2 3 4 5 6 7 8 9 10
。相关问题 更多 >
编程相关推荐