Python基本运算符

算数运算符

在这里插入图片描述

# + - * / % ** //  算数运算符
# 定义如下运算符
a=7
b=3
print(a+b)
print(a-b)
print(a*b)
print(a/b)
print(a%b)
print(a//b) # 地板除,相除取整,也可进行复合运算

在这里插入图片描述

比较运算符

在这里插入图片描述

# == != < > >= <= 比较运算符
a,b=10,5
print(a==b)
print(a!=b)
print(a<=b)
print(a>=b)
print(a<b)
print(a>b)

在这里插入图片描述

逻辑运算符

在这里插入图片描述

# and or not 逻辑运算符
# and  条件严格,都为真为真
# or 都为假为假
# not 非 真假切换,只需在前面加上not就可,对于需要取反操作的
a,b,c,d=23,16,26,56
print(a+b>c and c<d)
print(a>b or c<d)
print('--------not-------')
print(a>b)
print(not a>b)

在这里插入图片描述

# 优先级
# () -> not -> and -> or
print (2>1 and 1<4 or 2<3 and 9>6 or 2<4)

在这里插入图片描述

赋值运算符

在这里插入图片描述

# 赋值运算 (算术运算的补充)
# += -= /= %= **= *=
a=10
b=1
c=4
d=5
a+=c
print(a)
b*=d
print(d)
d**=c  ##数字为几即为几次方
print(d)

在这里插入图片描述

总结

本篇文章就到这里了,希望能够给你带来帮助,也希望您能够多多关注脚本之家的更多内容!

更多文章请关注《万象专栏》