摘要:本文主要介绍Python语言开发入门到精通之Python流程控制 ,通过具体的内容向大家展现,希望对大家Python程序开发的学习有所帮助。
本文主要介绍Python语言开发入门到精通之Python流程控制 ,通过具体的内容向大家展现,希望对大家Python程序开发的学习有所帮助。
代码块
是由多行语句组成,:开始。
条件判断语句
If语句
if 条件 :
做事情
else:
做事情
if 条件:
做事情
elif 条件:
做事情
else:
做事情1.2.3.4.5.6.7.8.9.10.11.12.
实验代码
# if 语句
score = 60
students = {"zhangsan":80,"lisi":70,"wangwu":40}
if students["wangwu"] >= score:
print("及格了")
elif students["zhangsan"] >= 80:
print("你很优秀")
else:
print("不及格")
a=True
b=True
if a == True:
print(True)
if b == 1:
print(False)1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.
输出
你很优秀1.
循环语句
for循环语句
for 变量名 in 序列:
todo1.2.
实验代码
#For 循环语句
students = ["aa","bbb","ccc","ddd"]
for i in students:
print("students's name is {0}".format(i))
for index in range(len(students)):
if students[index] == i:
print(index)1.2.3.4.5.6.7.8.9.10.
输出
students's name is aa
0
students's name is bbb
1
students's name is ccc
2
students's name is ddd
31.2.3.4.5.6.7.8.
while循环语句
while 条件=True:
todo1.2.
实验代码
#while 语句
a = 11
while a >= 10 :
for i in range(100):
print(i)
if i == 5:
a = i
print(a)1.2.3.4.5.6.7.8.9.10.
break continue语句
跳出循环
跳出当前循环,继续下次循环
#break continue
for i in range(10):
if i == 5:
break
else:
print(i)
for i in range(10):
if i == 5:
continue
else:
print(i)1.2.3.4.5.6.7.8.9.10.11.12.13.14.
迭代器
Iterable
#迭代器
#lterable
from collections import Iterable
num=456
print(isinstance(num, Iterable))
num1 = [1,2,3]
print(isinstance(num1, Iterable))1.2.3.4.5.6.7.8.9.10.11.
输出
False
True1.2.
enumerate
#enumerate
names = ['z','a','b']
print(enumerate(names))
for i,value in enumerate(names):
print(i,value)1.2.3.4.5.6.7.
0 z
1 a
2 b1.2.3.
列表推导式
#列表推导式
numlist = []
for x in range(5):
numlist.append(x)
print(numlist)
#
print([x for x in range(5)])1.2.3.4.5.6.7.8.9.
[0, 1, 2, 3, 4]
[0, 1, 2, 3, 4]1.2.
我是小职,记得找我
✅ 解锁高薪工作
✅ 免费获取基础课程·答疑解惑·职业测评
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号