0
点赞
收藏
分享

微信扫一扫

python 字典的不同取值方法


如果使用get(key)的方法取值,不存在的键胡返回空值

d = {"first":1}
print(d.get("first"))
print(d.get("second"))

结果:

1
None

但是如果直接取值,不存在的则会报错

print(d["first"])
print(d["second"])

python 字典的不同取值方法_取值

举报

相关推荐

0 条评论