“Python/gloss python check if tuple item exists”的版本间差异

来自菜鸟教程
跳转至:导航、​搜索
(Pywikibot 4.4.0.dev0)
 
(机器人:添加分类Python基础教程
 
第44行: 第44行:
 
</div>
 
</div>
 
<br />
 
<br />
 +
 +
[[分类:Python基础教程]]

2020年10月29日 (四) 08:48的最新版本

<languages />

Python检查元组项是否存在

检查元组项是否存在

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

检查元组中是否存在“苹果”:

thistuple = ("apple", "banana", "cherry")

  if "apple" in thistuple:
  print("Yes, 'apple' is in the fruits tuple")