Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在python中,不使用空格字符并排打印,内部为循环_Python - Fatal编程技术网

在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

对于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 in word:
...     sys.stdout.write(c)
...
spaces>>>

旁注:如上所示,您不需要使用索引;只需迭代字符串即可获得字符。

这可能的重复项正是我想要的。非常感谢你!