python如何判断元素在不在list中?
yang
2020-05-19 15:49:0818056浏览 · 0收藏 · 0评论
python中可以使用in操作符来判断元素在不在list中,in在Python中是操作符,具体来说是成员操作符。就是对于序列(字符串,元组,列表)或集合(set)或映射(字典)这些数据类型做成员判断。
示例:
abcList=['a','b','c',1,2,3] if 'c' in abcList: print("存在") else: print("不存在") if 'd' in abcList: print("存在") else: print("不存在")
输出结果:
存在
不存在
更多Python知识请关注Python自学网。
关注公众号,随时随地在线学习