操作符 | 描述 |
---|---|
** |
冪運算
|
~ + - |
補,一元加號和減號(方法名的最後兩個 +@ 和 -@)
|
* / % // |
乘,除,模運算和地板除
|
+ - |
加法和減法
|
>> << |
左,右按位元移動
|
& |
位元「與」
|
^ | |
按位元'互斥或'和常規 '或'
|
<= < > >= |
比較運算子
|
<> == != |
操作符相等比較
|
= %= /= //= -= += *= **= |
賦值運算子
|
is is not |
標識操作符
|
in not in | 成員操作符 |
not or and | 邏輯運算子 |
#!/usr/bin/python3 a = 20 b = 10 c = 15 d = 5 print ("a:%d b:%d c:%d d:%d" % (a,b,c,d )) e = (a + b) * c / d #( 30 * 15 ) / 5 print ("Value of (a + b) * c / d is ", e) e = ((a + b) * c) / d # (30 * 15 ) / 5 print ("Value of ((a + b) * c) / d is ", e) e = (a + b) * (c / d) # (30) * (15/5) print ("Value of (a + b) * (c / d) is ", e) e = a + (b * c) / d # 20 + (150/5) print ("Value of a + (b * c) / d is ", e)
a:20 b:10 c:15 d:5 Value of (a + b) * c / d is 90.0 Value of ((a + b) * c) / d is 90.0 Value of (a + b) * (c / d) is 90.0 Value of a + (b * c) / d is 50.0