基本运算符
运算 | 符号 | 表达式 |
---|---|---|
加 | + | a+b |
减 | - | a-b |
乘 | * | a*b |
除 | / | a/b |
取模(返回余数) | % | b%a |
幂 | ** | a**b |
取整 | // | a//b |
比较运算符
运算 | 符号 | 表达式 |
---|---|---|
等于 | == | (a==b)返回 False 或True |
不等于 | != | (a!=b) |
不等于 | <> | (a<>b) |
大于 | > | (a>b) |
小于 | < | (a<b) |
大于等于 | >= | (a>=b) |
小于等于 | <= | (a<=b) |
逻辑运算符
运算 | 符号 | 表达式 |
---|---|---|
与 | and | (a and b) 如果a为False,返回False,否则返回b的计算值。a=10,b=20,返回值为20。 |
或 | or | (a or b) 如果a非0,返回a的值,否则返回y的计算值。a=10,b=20,返回值为10。 |
非 | not | not(a and b) 如果a为True,返回False。如果x为False,返回True。返回False。 |
网友评论