1 Fork me on GitHub

Python常用数据结构-集合——1.2 集合使用:成员检测

1.2  集合使用:成员检测

in
   判断元素是否在集合中存在。如果存在,则返回True,不存在返回False
not in
   判断元素是否在集合中不存在。如果不在,则返回True,存在返回False


例子:

 

st = {1, 2, 3, 4, 5}
# in
print(2 in st)
print(6 in st)
# not in
print(99 not in st)
print(3 not in st)

返回

 

posted @ 2022-04-27 15:27  v_jjling  阅读(79)  评论(0编辑  收藏  举报
AmazingCounters.com