get()根据键获取字典中的值,如果键不存在则返回一个默认值,默认值不填写则返回None
1 a = { 2 "name":"dlrb", 3 "age":25, 4 "height":168 5 } 6 a1 = a.get("name") 7 a2 = a.get("ddd") 8 a3 = a.get("fff", "no find") 9 print(a1) 10 print(a2) 11 print(a3)
输出结果:
dlrb None no find