问题
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