python实现判断数组是否包含指定元素的方法
转载 2015-07-15 作者:企鹅不笨 我要评论
这篇文章主要介绍了python实现判断数组是否包含指定元素的方法,涉及Python中in的使用技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了python实现判断数组是否包含指定元素的方法。分享给大家供大家参考。具体如下:
python判断数组是否包含指定的元素的方法,直接使用in即可,python真是简单易懂
print 3 in [1, 2, 3] # membership (1 means true inventory = ["sword", "armor", "shield", "healing potion"] if "healing potion" in inventory: print "You will live to fight another day."
运行结果如下:
True
You will live to fight another day.
希望本文所述对大家的Python程序设计有所帮助。
您可能感兴趣的文章:
相关文章
python: line=f.readlines()消除line中\n的方法
这篇文章主要介绍了python: line=f.readlines()消除line中\n的方法,需要的朋友可以参考下2018-03-03Python 拷贝对象(深拷贝deepcopy与浅拷贝copy)
Python中的对象之间赋值时是按引用传递的,如果需要拷贝对象,需要使用标准库中的copy模块。2008-09-09
最新评论