Python print mystery – How to print without a space

Question:

How to have the same functionality as below in Python 2.7. No future please.

print(item, end="")
Asked By: User

||

Answers:

Would this work for you?

import sys
sys.stdout.write(item)
Answered By: Iman K

Before the wonderful end= (and sep=) appeared in Python 3, I used to build up lines within strings and the print out the string in one hit:

str = "Three integers:"
for iii in range (3):
    str = "%s %d" % (str, iii)
print s

Needless to say, I don’t code in Python 2 any more 🙂

Answered By: paxdiablo
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.