Python/gloss python check if dictionary item exists

来自菜鸟教程
机器人讨论 | 贡献2020年10月29日 (四) 08:48的版本 (机器人:添加分类Python基础教程
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至:导航、​搜索

<languages />

Python检查字典中是否存在键

检查字典中是否存在键

要确定字典中是否存在指定的键,请使用 in 关键词:

检查字典中是否存在“模型”:

thisdict =  {

  "brand": "Ford",

  "model": "Mustang",

  "year": 1964

}

  if "model" in thisdict:
  print("Yes, 'model' is 
  one of the keys in the thisdict dictionary")