# 算数运算符
a = 10
b = 20
print("a+b的结果是:",a+b)
print("a-b的结果是:",a-b)
print("a*b的结果是:",a*b)
print("a/b的结果是:",a/b)
print("b%a的结果是:",b%a)
print("a**b的结果是:",a**b)
print("5//2的结果是:",5//2)
运行结果
2) 赋值运算符
=、+=、-+、=、/=、%=、*=、//=
代码
# 赋值运算符
a = 10
b = 20
# a = a+b
a += b
print("a += b的结果是:",a)
a -= b
print("a -= b的结果是:",a)
a *= b
print("a *= b的结果是:",a)
a /= b
print("a /= b的结果是:",a)
a %= b
print("a %= b的结果是:",a)
运行结果
3) 比较运算符
==、!=、>、<、>=、<=
代码
# 比较运算符
a = 10
b = 20
print(a>b)
print(a<b)
print(a==b)
print(a!=b)
运行结果
4) 逻辑运算符
and、or、not
代码
# 逻辑运算符
a = 10
b = 20
if(a == 10 and b == 20):
print("yes")
else:
print("no")
if(a == 10 or b == 10):
print("yes")
else:
print("no")
a = False
if(not a):
print("yes")
else:
print("no")