小职
2021-07-30
来源 :
阅读 942
评论 0
摘要:本文主要介绍Python语言开发入门到精通之Python流程控制 ,通过具体的内容向大家展现,希望对大家Python程序开发的学习有所帮助。
本文主要介绍Python语言开发入门到精通之Python流程控制 ,通过具体的内容向大家展现,希望对大家Python程序开发的学习有所帮助。

算数运算符
+ 加法运算
- 减法运算
* 乘法运算
/ 除法运算
% 模运算
** 幂运算
// 整除运算1.2.3.4.5.6.7.
实验笔记
numOne = 10
numTwo = 20
print("numOne + numTwo = %d" %(numOne + numTwo) )
print("numOne - numTwo = %d" %(numOne - numTwo) )
print("numOne * numTwo = %d" %(numOne * numTwo) )
print("numOne / numTwo = %d" %(numOne / numTwo) )
print("numOne % numTwo = {0}".format(numOne % numTwo ) )
print("numOne ** numTwo = %d" %(numOne ** numTwo))
print("numTwo // numOne = %d" %(numTwo // numOne) )1.2.3.4.5.6.7.8.9.10.11.
比较运算符
== 等于运算符
!= 不等于
> 大于
< 小于
>= 大于等于
<= 小于等于
返回值是布尔类型 True False1.2.3.4.5.6.7.8.
实验源码
#比较运算符
number1 = 123
number2 = 456
#todo
print("number1 == number2 is ---> {0}".format(number1 == number2))
print("number1 != number2 is ---> {0}".format(number1 != number2))
print("number1 > number2 is ---> {0}".format(number1 > number2))
print("number1 < number2 is ---> {0}".format(number1 < number2))
print("number1 >= number2 is ---> {0}".format(number1 >= number2))
print("number1 <= number2 is ---> {0}".format(number1 <= number2))1.2.3.4.5.6.7.8.9.10.11.
赋值运算符
= 将右侧的值分配给左侧
+= 先相加然后将结果赋值给左侧
-= 先相减然后将结果赋值给左侧
*= 先相乘然后将结果赋值给左侧
/= 先相除然后将结果赋值给左侧
%= 先求模然后将结果赋值给左侧
**= 先幂运算然后将结果赋值给左侧
//= 先整除然后将结果赋值给左侧1.2.3.4.5.6.7.8.
实验源码
result = 10
print(result)
num1 = 10
num2 = 20
num1 = num2
print("num1 = num2 ---> {0} ".format(num1))
num1 += num2
print("num1 += num2 ---> {0}".format(num1))
num1 -= num2
print("num1 -= num2 ---> {0}".format(num1))
num1 *= num2
print("num1 *= num2 ---> {0}".format(num1))
num1 /= num2
print("num1 /= num2 ---> {0}".format(num1))
num1 %= num2
print("num1 %= num2 ---> {0}".format(num1))
num1 **= num2
print("num1 **= num2 ---> {0}".format(num1))
num1 //= num2
print("num1 //= num2 ---> {0}".format(num1))1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.
控制台输出
10
num1 = num2 ---> 20
num1 += num2 ---> 40
num1 -= num2 ---> 20
num1 *= num2 ---> 400
num1 /= num2 ---> 20.0
num1 %= num2 ---> 0.0
num1 **= num2 ---> 0.0
num1 //= num2 ---> 0.01.2.3.4.5.6.7.8.9.
逻辑运算符
and 逻辑与 两边所有为True 则True 否则 False
or 逻辑或 两边任意为True 则True 否则False
not 逻辑非 如果为True 则为False 变量为False 返回True1.2.3.
实验源码
A = True
B = False
print("A and B ---> {0}".format(A and B))
print("A or B ---> {0}".format( A or B))
print("not A ---> {0}".format(not A))
print("not B ---> {0}".format(not B))1.2.3.4.5.6.7.
控制台输出
A and B ---> False
A or B ---> True
not A ---> False
not B ---> True1.2.3.4.
成员运算符
in 存在 返回True False
not in 不存在 True False1.2.
实验 源码
# 成员运算符
student = ["zhangsan","lisi","wangwu"]
print("xiaoming is my student ? -->{0}".format("xiaoming" in student))
print("xiaohua is not my student ? -->{0}".format("xiaohua" not in student))
print("zhangsan is my student? -->{0}".format("zhangsan" in student))1.2.3.4.5.6.7.
控制台输出
xiaoming is my student ? -->False
xiaohua is not my student ? -->True
zhangsan is my student? -->True1.2.3.
身份运算符
is 如果两个对象为同一个内存地址返回True false
is not 不相同返回True false1.2.
实验源码
#身份运算符
num1 = 10
num2 = 10
print("num1 is num2 --> {0}".format(num1 is num2))
print("num1 is not num2 --> {0}".format(num1 is not num2))
a = "123"
b = "123"
print("a is b --> {0}".format(a is b))1.2.3.4.5.6.7.8.9.10.11.
控制台输出
num1 is num2 --> True
num1 is not num2 --> False
a is b --> True1.2.3.
位运算符
& 位于运算
| 位或运算
^ 异或运算
~ 位取反1.2.3.4.
实验源码
#位运算符
num1 = 1000101
num2 = 10101
print("num1 & num2 = {0}".format(num1&num2))
print("num1 | num2 = {0}".format(num1|num2))
print("num1 ^ num2 = {0}".format(num1^num2))
print("~num1 = {0}".format(~num1))
print("~num2 = {0}".format(~num2))1.2.3.4.5.6.7.8.9.
控制台输出
num1 & num2 = 549
num1 | num2 = 1009653
num1 ^ num2 = 1009104
~num1 = -1000102
~num2 = -101021.2.3.4.5.
运算符优先级
登录后复制
**
~ + -
* / % //
+ -
>> <<
&
^|
<= <> >=
= %= /+= //= -+ += *= **=
is is not
in not in
not or and
我是小职,记得找我
✅ 解锁高薪工作
✅ 免费获取基础课程·答疑解惑·职业测评

喜欢 | 0
不喜欢 | 0
您输入的评论内容中包含违禁敏感词
我知道了

请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式AI+学习就业服务平台 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号