-4

How to remove spaces in this print ?

For example

for i in range(5):
print i,

Will prints: 1 2 3 4 5

But I would like to get print like: 12345

Someone can help ?

ReVaN
  • 15
  • 5

1 Answers1

0

In Python 3, you can use:

for i in range(5):
    print(i, end="")

In Python 2, however you can not achieve it via simple print. There are two ways to do it:

# Way 1: Using "sys.stdout". But this will write to stdout 
>>> import sys
>>> for i in range(5):
...     sys.stdout.write(str(i))
... 
01234>>>

# Way 2: Convert it to list of string and then join them
>>> print ''.join(map(str, range(5)))
01234
Moinuddin Quadri
  • 46,825
  • 13
  • 96
  • 126