码迷,mamicode.com
首页 > 编程语言 > 详细

python 基础 4 常用的运算符

时间:2018-01-25 23:09:32      阅读:227      评论:0      收藏:0      [点我收藏+]

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

标签:play   gpo   list   技术分享   wrong   display   src   逻辑运算   .com   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!