当前位置:首页 > 行业动态 > 正文

Python运算符与或非

Python运算符

1、算术运算符

Python运算符与或非  第1张

加法:+

减法:

乘法:*

除法:/

取模:%

整除://

幂运算:**

2、比较运算符

等于:==

不等于:!=

大于:>

小于:<

大于等于:>=

小于等于:<=

3、逻辑运算符

与:and

或:or

非:not

示例代码

算术运算符
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("a % b =", a % b)
print("a // b =", a // b)
print("a  b =", a  b)
比较运算符
print("a == b:", a == b)
print("a != b:", a != b)
print("a > b:", a > b)
print("a < b:", a < b)
print("a >= b:", a >= b)
print("a <= b:", a <= b)
逻辑运算符
x = True
y = False
print("x and y:", x and y)
print("x or y:", x or y)
print("not x:", not x)
0