python 基础 4 常用的运算符
Posted 王子之心
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 基础 4 常用的运算符相关的知识,希望对你有一定的参考价值。
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
以上是关于python 基础 4 常用的运算符的主要内容,如果未能解决你的问题,请参考以下文章