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

疆括仕网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

创新互联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://tyhkzb.com/article/dhehdeg.html
在线咨询
服务热线
服务热线:028-86922220
TOP