1.成员运算符
运算符 | 描述 | 实例 |
in | 如果在指定的序列中找到值返回True, 否则返回False | x 在y 序列中, 如果x 在y 序列中返回True |
not in | 如果在指定的序列中没有找到值返回 True,否则返回False | x 不在y 序列中, 如果x 不在y 序列中返回True |
a = 10
b = 20
list = [1, 2, 3, 4, 5 ]
if ( a in list ):
print ("1 - 变量a 在给定的列表中list中")
else:
print ("1 - 变量a 不在给定的列表中list 中")
2.身份运算符
运算符 | 描述 | 实例 |
is | is 是判断两个标识符是不是引用自一个对象 | x is y, 类似id(x) == id(y) , 如果引用的是同一个对象则返回True,否则返回False |
not is | not is not 是判断两个标识符是不是引用自不同对象 | x is not y ,类似id(a) != id(b)。如果引用的不是同一个对象则返回结果True,否则返回False |
使用函数判断用户传入的对象(字符串、列表、元组)的值是否有空值
def shifou_space(args):
ret = True
for a in args:
if a.isspace():
ret = False
break
return ret
result = shifou_space("123 12312")
print("有空格",result)
isspace()