和小白学编程 --------> Python运算符优先级( 二 )

not and or逻辑运算符

以下实例演示了Python所有运算符优先级的操作:

实例(Python 3.0+)

#!/usr/bin/python3

a=20

b=10

c=15

d=5

e=0

e=(a+b)*c/d#( 30 * 15 ) / 5

print(\"(a + b) * c / d 运算结果为:\"e)

e=((a+b)*c)/d# (30 * 15 ) / 5

print(\"((a + b) * c) / d 运算结果为:\"e)

e=(a+b)*(c/d);# (30) * (15/5)

print(\"(a + b) * (c / d) 运算结果为:\"e)

e=a+(b*c)/d;#  20 + (150/5)

print(\"a + (b * c) / d 运算结果为:\"e)

推荐阅读