for x in range(1, 11):
print repr(x).rjust(2), repr(x*x).rjust(3),
# Note trailing comma on previous line
print repr(x*x*x).rjust(4)
It stops print
from printing a newline at the end of the text.
As Dave pointed out, the documentation in python 2.x says: …. "A '\n' character is written at the end, unless the print statement ends with a comma."
UPDATE:
The documentation of python 3.x states that print()
is a function that accepts the keyword argument end
which defaults to a newline, \n
.