本文共 359 字,大约阅读时间需要 1 分钟。
Python成员运算符 in 是判断值在某个列表中就返回True ,
Python成员运算符 not in 是判断值不在某个列表中就返回True ,
下面是简单的一个list 帮助理解
list_a = [1, 2, 3, 4, 5, 6]a = 3b = 19if a in list_a: print("%d 在list_a中" % a) print(a in list_a) # 返回为Trueelse: print("%d 不在list_a中" % a)if b not in list_a: print("%d 不在list_a中" % b) print(b not in list_a) # 返回为Trueelse: print("%d 在list_a中" % b)
转载地址:http://grfif.baihongyu.com/