num += 1 等价于 num = num + 1
num -= 2 等价于 num = num - 2
num *= 3 等价于 num = num * 3
num /= 5 等价于 num = num / 5
num //= 7 等价于 num = num // 7
num %= 8 等价于 num = num % 8
num **= 9 等价于 num = num ** 9
luoji = True or True and False print(luoji) #先运算and ,然后在运算or,and的优先级较高 结果: True
逻辑运算符
list1 = [1,2,3,4,5,18,32,16 ] a = 10 b = 32 if a not in list1: print("correct,%s is not in %s"%(a,list1)) else: print("wrong,%s is not in %s"%(a,list1)) if b in list1: print("correct,%s is in %s" % (b, list1)) else: print("wrong,%s is not in %s" % (b, list1)) 结果: correct,10 is not in [1, 2, 3, 4, 5, 18, 32, 16] correct,32 is in [1, 2, 3, 4, 5, 18, 32, 16]
成员运算符
#身份运算符 is not is a = 10 b = 32 if a is b: print("correct,%s is %s"%(a,b)) if a is not b : print("correct,%s is not %s" % (a,b )) a = 10 b = 10 if a is b: print("correct,%s is %s"%(a,b)) if a is not b : print("correct,%s is not %s" % (a,b )) 结果: correct,10 is not 32 correct,10 is 10
身份运算符
原文地址:https://www.cnblogs.com/jiaaoblog/p/8353438.html
时间: 2024-10-07 04:45:40