成都网站建设设计

将想法与焦点和您一起共享

创新互联Python教程:python判断list中某一元素是否存在

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

例如:

abcList=['a','b','c',1,2,3]
    if 'a' in abcList:
        print('a is in abcList')
    if 'd' not in abcList:
        print('d is not in abcList')
    if 1 in abcList:
        print('1 is in abcList')

结果为:


文章题目:创新互联Python教程:python判断list中某一元素是否存在
标题网址:https://chengdu.cdxwcx.cn/article/dhehdeg.html