gpt4 book ai didi

python - 打印列表中的所有项目,它们之间有两个空格

转载 作者:太空宇宙 更新时间:2023-11-04 09:38:16 26 4
gpt4 key购买 nike

因此,我正在为我的大学作业使用 Python 3 编写一个刽子手游戏。我有这几行代码,这让我很头疼:

word = ['_' for i in range(len(chosen_word))]
print("The word is:", *word)

我有一个 5 个字母的单词的输出:

The word is: _ _ _ _ _

但我实际上需要这样的输出(项目之间的额外空间):

The word is: _  _  _  _  _

我应该怎么做?

感谢您的关注和帮助! :)

最佳答案

您可以使用带双空格的 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=' ')

关于python - 打印列表中的所有项目,它们之间有两个空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52755508/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com