小甲鱼-006操作运算符

结合菜鸟教程完善

"算术操作符"
"+ - * / //只保留商的整数部分 %只保留余数 **幂运算 "
a = 6
b = 3
c = a + 3
print("%s + 3 = %s" % (a, c))
d = b - 1
print("%s - 1 = %s" % (b, d))
e = a * b
print("%s * %s = %s" % (a, b, e))
f = c / d
print("%s / %s = %s" % (c, d, f))
g = c // d
print("%s // %s = %s" % (c, d, g))
h = c % d
print("%s %% %s = %s" % (c, d, h))
i = a ** b
print("%s ** %s = %s" % (a, b, i))


"+= -= *= /="
a = b = 1
a += 3
print("%s += 3: %s" % (b,a))
a = b = 1
a -= 3
print("%s -= 3: %s" % (b,a))
a = b = 1
a *= 3
print("%s *= 3: %s" % (b,a))
a = b = 1
a /= 3
print("%s /= 3: %s" % (b,a))

"逻辑运算符< <= > >= == !="
"逻辑操作负and or not"
print(5 > 3 and 4 > 3)
print(5 < 3 or 4 > 3)
print(not 4 < 3)
"优先级:幂运算 正负号 算术操作符 比较操作符 逻辑操作符"
posted on 2018-12-10 03:22  singleSpace  阅读(188)  评论(0编辑  收藏  举报