如果使用get(key)的方法取值,不存在的键胡返回空值
d = {"first":1}
print(d.get("first"))
print(d.get("second"))
结果:
1
None
但是如果直接取值,不存在的则会报错
print(d["first"])标签:get,python,second,报错,print,字典,取值,first From: https://blog.51cto.com/u_13866182/5857541
print(d["second"])
如果使用get(key)的方法取值,不存在的键胡返回空值
d = {"first":1}
print(d.get("first"))
print(d.get("second"))
结果:
1
None
但是如果直接取值,不存在的则会报错
print(d["first"])标签:get,python,second,报错,print,字典,取值,first From: https://blog.51cto.com/u_13866182/5857541
print(d["second"])