成员运算符
print(1 in[1,'2m'])
print(1 not in[1,'2m'])
print('c' in {'c':1})
print(1 in {'c':1})
比较运算符
print(1 == 1)
print(1 >= 1)
print(1 <= 1)
print(1 > 1)
print(1 < 1)
print(1 != 1)
b = 1
b += b >= 1
print(b>=1)
print(int(True))
print(b)
算术运算符
print(1 + 1)
print(1 - 1)
print(1 * 1)
print(4 / 2)
print(7 % 2)
print(2 ** 2)
print(2 ** 5)
赋值运算符
a = 1
a = a + 1
print(a)
a += 1
print(a)
身份运算符
'''
总结:
对象的三个特征 id value type
只有三个特征都相等时 使用 is 的结果才为True
而使用==时只需要value的结果就是True
'''
print(1 is 1)
print(1 is not 2)
print('1' is 1)
print(1 is 1.0)
print(1 == 1.0)
print(1 == True)
print(1 is True)
a = {1, 2, 3}
print(id(a))
b = {1, 3, 2}
print(id(b))
print(a == b)
print(a is b)
print(type(1) == int)
print(isinstance(1, int))
print(isinstance("2", str))
print(isinstance(1, (int, str, float)))
print(isinstance({1: 1}, (int, str, float)))
逻辑运算符
print(True and True)
print(False and True)
print(False and False)
print(True or True)
print(False or True)
print(False or False)
|