【发布时间】:2019-10-31 10:43:11
【问题描述】:
现在,我正在学习 Python,我想制作一个字典,用户可以在其中添加单词(第一步只是单词,稍后定义)。
word = input('Write a word here')
print('You added ' + word)
所以,我希望用户可以添加更多单词,然后程序将其保存到其他字符串。 我该怎么做?
【问题讨论】:
-
能否提供一个合适的输出样本。
-
对于具有 3 个用户输入词作为键和无值的字典:
dict.fromkeys(input('Write a word here') for i in range(3)) -
@Chris_Rands:提问者似乎更有可能想要一本字典,而不是 Python 数据结构的字典。
dict是否合适,以及这样的 dict 可能是什么样子,将取决于他们想要对数据做什么。
标签: python string automation