“print x,” equivalent in Python3

孤街醉人 提交于 2019-12-24 09:26:51

问题


Basically, I want to print out a string of values in a single line, in Python2 a statement like this one would suffice:

print x,

How to write the same simple statement in Python3 (i.e., without using any special formatting) ?


回答1:


>>> print(1, end=' '); print(2)
1 2

For further enlightenment:

>>> help(print)



回答2:


Here is an explanation from the following site:

http://docs.python.org/release/3.0.1/whatsnew/3.0.html

See the section called "Print Is A Function."

Old: print x, # Trailing comma suppresses newline

New: print(x, end=" ") # Appends a space instead of a newline




回答3:


In Python 3.x you would say:

print(x, end='')

Not sure what you mean by 'special formatting'.



来源:https://stackoverflow.com/questions/8914172/print-x-equivalent-in-python3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!