逗号运算符在 Python 3 中不起作用

Comma operator not work in Python 3

python 2中,在语句末尾使用逗号运算符以水平行打印输出.像这样:

for i in range(5):
    print i,

以上代码将生成以下输出:

0 1 2 3 4

但是,在 Python 3 中,逗号运算符无法以水平行打印输出。

for i in range(5):
    print (i),

生成以下输出:

0
1
2
3
4

那么,如何在 python 3 中水平打印输出?

在Python 3中你可以将结束参数传递给print函数来改变行尾字符

for i in range(5):
    print(i, end=" ")

>> 0 1 2 3 4