【发布时间】:2023-01-08 15:41:16
【问题描述】:
D1={'1':"aa", '2':"bb", '3':"cc"}
D1['4']
Traceback (most recent call last):
File "<pyshell#15>", line 1, in <module>
D1['4']
KeyError: '4'
使用字典时显示的 KeyError
【问题讨论】:
-
正如错误中明确指出的那样,您的 D1 字典没有
4键。你的问题到底是什么?你希望D1['4']做什么?
标签: python python-3.x