大宇私人领地伊甸园丨宁愿做了后悔,也不要错过后悔[www.mrdayu.com]
注册

24小时联系邮箱:[email protected]

编程人生
大宇私人伊甸园: 首页 > 编程人生 > Python语言 > Python3入门 > [009]操作运算符优先级

[009]操作运算符优先级

发布时间:2017/12/12 Python3入门 标签python3.6阅读:98

图解:

文字详解:

操作符 描述
**
幂运算
~ + –
补,一元加号和减号(方法名的最后两个 [email protected] 和 [email protected])
* / % //
乘,除,模运算和地板除
+ –
加法和减法
>> <<
左,右按位移动
&
位元“与”
^ |
按位’异或’和常规 ‘或’
<= < > >=
比较运算符
<> == !=
操作符相等比较
= %= /= //= -= += *= **=
赋值运算符
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

The bottom line, for me, is simple.

Let’s hope it doesn’t take 500 years for a discipline of testing to becomes the standard for software developers.

From:dayu

您好!请登录

合作网站快捷登录:
点击取消回复

已有0评论

    大宇博客

    点击这里给我发消息点击这里给我发消息