Python 检查字典中是否存在某个键
检查字典中是否存在某个键
要确定字典中是否存在指定的键,请使用 in
关键字:
实例
检查字典中是否存在 "model":
thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } if "model" in thisdict: print("是的,'model' 是 thisdict 字典中的一个键")
要确定字典中是否存在指定的键,请使用 in
关键字:
检查字典中是否存在 "model":
thisdict = { "brand": "Ford", "model": "Mustang", "year": 1964 } if "model" in thisdict: print("是的,'model' 是 thisdict 字典中的一个键")