python字典get()方法和[key]区别

279 阅读1分钟

记录一下问题

dic.get(key[,fault]) ,当key不存在不会抛出异常,会显示fault信息
dic[key],当key不存在会抛出 KeyError 错误