在 ,可以使用函数的end
参数print()
来防止换行符被打印:
print("Nope, that is not a two. That is a", end="")
在 ,可以使用尾部逗号:
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()
。