Monday, June 20, 2016

Printing without newline

Print automatically adds a new line after printing its input variables and/or constants. To avoid this new line in Python2.6+ you can add a colon "," (without quotes) after the printing command, here is an example
print 'Hello',
print 'World'
In Python3, you can add the option end="". Example:
Remember that from Python2.6+ you also can use the Python3 print command, adding
from __future__ import print_function

No comments:

Post a Comment