首页 > 编程语言 > 详细

python 基础 4 常用的运算符

时间:2018-01-25 22:55:12      阅读:257      评论:0      收藏:0      [点我收藏+]

技术分享图片

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 常用的运算符

原文:https://www.cnblogs.com/jiaaoblog/p/8353438.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!