【发布时间】:2017-04-02 01:29:46
【问题描述】:
我有一个分配了多个值的键。我想要求用户输入 (new_population),并替换键中的旧值 (current_population)。我希望键 (num) 中的其他值不受影响。
current_population = 5
num = 3
dict = {}
dict["key"] = [current_population, num]
new_population = input("What is the new population?")
说(例如清酒),new_population 的值为 10。我的目标是最终输出:
{'key': [10, 3]}
我该怎么做呢?
【问题讨论】:
-
你知道 dict 是一个内置对象吗?不要将变量名用作 dict 以防万一您的模块/代码的其他部分需要内置函数
-
是的,我愿意。回想起来,我应该使用不同的名称,但我只是认为这是说它是字典的最明显方式。
标签: python dictionary key