Python/gloss python check if list item exists

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

<languages />

Python检查列表项是否存在

检查列表项是否存在

要确定列表中是否存在指定的项目,请使用 in 关键词:

检查列表中是否存在“苹果”:

thislist = ["apple", "banana", "cherry"]

  if "apple" in thislist:
  print("Yes, 'apple' is in the fruits list")