Methods for printing without adding control characters in python
python, python-2.7, python-2.x
Solution
Python 3.x:
print(string, end="")
Python 2.x:
from __future__ import print_function
print(string, end="")
or
print string, # This way adds a space at the end.
From the second answer of the duplicate question, I got this idea:
Instead of something like this:
>>> for i in xrange(10):
print i,
1 2 3 4 5 6 7 8 9 10
you might be able to do this:
>>> numbers = []
>>> for i in xrange(10):
numbers.append(i)
>>> print "".join(map(str, numbers))
12345678910
I would recommend `import`ing `print_function`. Or (tongue-in-cheek answer) upgrading to Python 3.x!
Problem
I have been using the function `sys.stdout.write(string)` but I was wondering if there is another method for this purpose. Thanks in advance!