因此,我正在用python 3编写一个子手游戏供我的大学学习。我有这几行代码让您很痛苦:
word = ['_' for i in range(len(chosen_word))]
print("The word is:", *word)
我的输出是5个字母的单词:
The word is: _ _ _ _ _
但是我实际上需要这样的输出(项目之间有一个额外的空格):
The word is: _ _ _ _ _
关于我应该怎么做的任何想法?
感谢您的关注和帮助! :)
答案 0 :(得分:2)
您可以将sep
参数使用双倍空格:
word = ['_' for i in range(len(chosen_word))]
print("The word is:", *word, sep=' ')
如果您不希望':'之后的双倍空格,请使用两种不同的打印方法:
word = ['_' for i in range(len(chosen_word))]
print("The word is:", end=' ')
print(*word, sep=' ')
答案 1 :(得分:2)
一种简单的方法是:
string = ' '.join(words)
print("The word is:", string)
答案 2 :(得分:0)
word = ['_ 'for i in range len(chosen_word)]
print("The word is:", *word)
您可以简单地做到这一点