首页 > 编程语言 > 详细

Python成员运算符

时间:2020-02-05 17:23:48      阅读:71      评论:0      收藏:0      [点我收藏+]

Python成员运算符:

  in:如果左面的对象右面的对象中,则返回 True,不在则返回 False。

 not in:如果左面的对象不在右面的对象中,则返回 True,在则返回 False。

# 分别在列表、字符串、元组、字典和集合中使用。
# in 在则返回 True , 不在则返回 False
a = a
d = d
lst = [a,b,c]
# 判断 a 是否在 lst 中
print(a in lst)
# True
# 判断 d 是否在 lst 中
print(d in lst)
# False

a = a
d = d
strs = abc
# 判断 a 是否在 strs 中
print(a in strs)
# True
# 判断 d 是否在 strs 中
print(d in strs)
# False

a = a
d = d
tup = (a,b,c)
# 判断 a 是否在 tup 中
print(a in tup)
# True
# 判断 d 是否在 tup 中
print(d in tup)
# False

a = a
d = d
dic = {a:123,b:456,c:789}
# 判断 a 是否在 dic 中
# 字典主要是看,是否存在该键
print(a in dic)
# True
# 判断 d 是否在 s 中
print(d in dic)
# False

a = a
d = d
s = {a,b,c}
# 判断 a 是否在 s 中
print(a in s)
# True
# 判断 d 是否在 s 中
print(d in s)
# False

# not in , 不在返回 True ,在返回 False
# 分别在列表、字符串、元组、字典和集合中使用。
a = a
d = d
lst = [a,b,c]

# 判断 a 是否不在 lst 中
print(a not in lst)
# False
# 判断 d 是否在 lst 中
print(d not in lst)
# True

a = a
d = d
strs = abc

# 判断 a 是否不在 strs 中
print(a not in strs)
# False
# 判断 d 是否不在 strs 中
print(d not in strs)
# True

a = a
d = d
tup = (a,b,c)

# 判断 a 是否不在 tup 中
print(a not in tup)
# False
# 判断 d 是否不在 tup 中
print(d not in tup)
# True

a = a
d = d
dic = {a:123,b:456,c:789}
# 字典主要是看,是否存在该键

# 判断 a 是否不在 dic 中
print(a not in dic)
# False
# 判断 d 是否不在 dic 中
print(d not in dic)
# True

a = a
d = d
s = {a,b,c}
# 判断 a 是否不在 s 中
print(a not in s)
# False
# 判断 d 是否不在 s 中
print(d not in s)
# True

2020-02-05

Python成员运算符

原文:https://www.cnblogs.com/hany-postq473111315/p/12263573.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!