python 中如何判断list中是否包含某个元素

在python中可以通过in和not in关键字来判读一个list中是否包含一个元素

theList = ['a','b','c']
if 'a' in theList:
    print 'a in the list'
else:
    print 'a is not in the list'
if 'd' not in theList:
    print 'd is not in the list'
else:
    print 'd in the list'

 

posted @ 2019-02-18 11:39  Christina_笔记  阅读(7930)  评论(0编辑  收藏  举报