在python中,不使用空格字符并排打印,内部为循环
对于python中的这段代码在python中,不使用空格字符并排打印,内部为循环,python,Python,对于python中的这段代码 >>>word="spaces" >>>for i in range(len(word)): ... print word[i], ... s p a c e s >>> 如果我不希望打印的字母之间有空格,我该怎么办?在C for eg中,打印默认位于最后一个打印字符的旁边 使用sys.stdout.write: >>> word = 'spaces' >>> for c
>>>word="spaces"
>>>for i in range(len(word)):
... print word[i],
...
s p a c e s
>>>
如果我不希望打印的字母之间有空格,我该怎么办?在C for eg中,打印默认位于最后一个打印字符的旁边 使用
sys.stdout.write
:
>>> word = 'spaces'
>>> for c in word:
... sys.stdout.write(c)
...
spaces>>>
旁注:如上所示,您不需要使用索引;只需迭代字符串即可获得字符。这可能的重复项正是我想要的。非常感谢你!