python中的运算符

(1)算数运算:(a=10,b=5)
# + 加号 a + b >>> 15
# - 减号 a - b >>> 5
# * 乘号 a * b >>> 50
# / 除号 a / b >>> 2
# % 取模(获取除法的余数) 10 % 3 >>> 1 (商是3,余数是1,获取1)
# ** 幂(次方) a ** 2 >>> 100
# // 取整除(取商的整数部分) 10 // 3 >>> 3

(2)比较运算:(a=10,b=5)
# == 比较两边是否等于 a == b >>> False
# != 比较两边是否不等于 a != b >>> True
# > 比较左是否大于右 a > b >>> True
# < 比较左是否小于右 a < b >>> False
# >= 比较左是否大于等于右 a >= b >>> True
# <= 比较左是否小于等于右 a <= b >>> False

(3)赋值运算:(a=10,b=5)
# += a += b >>> 15 (a = a + b)
# -= a -= b >>> 5 (a = a - b)
# *= a *= b >>> 50 (a = a * b)
# /= a /= b >>> 2 (a = a / b)
# %= a %= 3 >>> 1 (a = a % 3)
# **= a **= 2 >>> 100 (a = 10的2次方)
# //= a //= 3 >>> 3 (a = a // 3)

(4)逻辑运算:(x = 20,y = 10)
# and :布尔(与),如果x为false,x and y就返回false,否则它返回y的计算值
# x == 20 and y == 10 >>>True
# x == 21 and y == 10 >>>False
# x == 20 and y == 11 >>>False
# or :布尔(或),如果x为True,它返回True,否则它返回y的计算值
# x == 20 or y == 10 >>>True
# x == 21 or y == 10 >>>True
# x == 20 or y == 11 >>>True
# x == 21 or y == 11 >>>False
# not :布尔(非),如果x为True,它返回false,如果x为false,它返回True
# not x == 20 >>>False
# not x == 21 >>>True
# not x == 21 or y == 11 >>>True
# not x == 21 and y == 11 >>>False
posted @ 2018-11-21 08:33  队长给我球  阅读(146)  评论(0编辑  收藏  举报