Methods for printing without adding control characters in python
This question already has an answer here:
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!
下一篇: 在python中不添加控制字符的打印方法