標籤:play gpo list 技術分享 wrong display src 邏輯運算 .com
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 Falseprint(luoji)#先運算and ,然後在運算or,and的優先順序較高結果:True
邏輯運算子
list1 = [1,2,3,4,5,18,32,16 ]a = 10b = 32if 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 isa = 10b = 32if a is b: print("correct,%s is %s"%(a,b))if a is not b : print("correct,%s is not %s" % (a,b ))a = 10b = 10if 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 32correct,10 is 10身份運算子
python 基礎 4 常用的運算子