This question already has an answer here:
- How to print without newline or space? 26 answers
In python, if I say
print 'h'
I get the letter h and a newline. If I say
print 'h',
I get the letter h and no newline. If I say
print 'h',
print 'm',
I get the letter h, a space, and the letter m. How can I prevent Python from printing the space?
The print statements are different iterations of the same loop so I can't just use the + operator.
Or use a
+
, i.e.:Just make sure all are concatenate-able objects.
Regain control of your console! Simply:
where
__past__.py
contains:then:
Bonus extra: If you don't like
print >> f, ...
, you can extending this caper to fprintf(f, ...).But really, you should use
sys.stdout.write
directly.In python 2.6:
So using print_function from __future__ you can set explicitly the sep and end parameteres of print function.