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.
Greg is right-- you can use sys.stdout.write
Perhaps, though, you should consider refactoring your algorithm to accumulate a list of <whatevers> and then
I had the same problem once I wanted to read some digits from a file. I solved it like this:
This may look stupid, but seems to be the simplest:
Just a comment. In Python 3, you will use
to suppress the endline terminator, and
to suppress the whitespace separator between items.
You can use: