查找 Mistake: Missing 键 Access
找错误 简单
题目
这个 code raises KeyError. 什么是 错误?
代码
d = {"name": "Alice"}
print(d["age"])
提示
检查如果键 exists in dictionary.
解释
The key "age" is not in the dictionary. The fix is to use d.获取("age") (returns None) or d.获取("age", "unknown") (returns a default) instead of d["age"].
相关资源
相关课程
- Dictionaries
Safe 键 access.
查阅不认识的术语
新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。
动手做项目
通过引导式项目应用所学,含起始代码与解决方案。