0

for this code in python,

>>>word="spaces"
>>>for i in range(len(word)):
...   print word[i],
...
s p a c e s
>>>

If I do not want any spaces in between the letters that are printed, what should I do ? In C for eg, the printing is by default next to the last printed character.

user44477
  • 1
  • 1
  • Possible duplicate of http://stackoverflow.com/questions/493386/how-to-print-in-python-without-newline-or-space – damgad Oct 09 '14 at 15:39

1 Answers1

1

Use sys.stdout.write:

>>> word = 'spaces'
>>> for c in word:
...     sys.stdout.write(c)
...
spaces>>>

Side note: As you can see above, you don't need to use indexes; Just iterate the string to get characters.

falsetru
  • 357,413
  • 63
  • 732
  • 636