Python/gloss python check if dictionary item exists

来自菜鸟教程
跳转至:导航、​搜索

<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")