在Python 2.x中,我会写...

for i in range(5):
    print i,

...要使整数从0到4打印在同一行中。如何在Python 3.X中执行此操作,因为PRINT现在是一个函数?

有帮助吗?

解决方案

利用 print(x, end = ' '):

来自 发行说明:

Old: print x,           # Trailing comma suppresses newline  
New: print(x, end=" ")  # Appends a space instead of a newline
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top