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')

结果为:

猜你喜欢

转载自www.cnblogs.com/shenxiaolin/p/11101766.html