3

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!

Frandman
  • 43
  • 3

1 Answers1

11

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 importing print_function. Or (tongue-in-cheek answer) upgrading to Python 3.x!

rlms
  • 10,650
  • 8
  • 44
  • 61
  • Thank you, the problem with this is that i also don't want an extra space, i'll edit my question ;) – Frandman Dec 04 '13 at 16:18