在 Python 3.x中 ,可以使用函数的
end参数
print()来防止换行符被打印:
print("Nope, that is not a two. That is a", end="")在 Python 2.x中 ,可以使用尾部逗号:
print "this should be",print "on the same line"
不过,您不需要此即可简单地打印变量:
print "Nope, that is not a two. That is a", x
请注意,尾部逗号仍会导致在行尾打印一个空格,即等同于
end=" "在Python 3中使用。要抑制空格字符,也可以使用
from __future__ import print_function
可以访问Python 3打印功能或使用
sys.stdout.write()。



