三、 Python控制流
顺序结构
就是我们写的代码按照顺序执行代码
分支结构
if else 当业务逻辑判断某个条件成立时,可以使用if else
# if 条件:
# 执行条件语句A(statements)
# else:
# 执行条件语句B(statements)
if
循环结构
while循环
# 条件成立 一直执行 直到条件不不成立 终止执行
#一般break与continue配合使用
#break:强制停止该循环 退出该循环
#continue:强制停止本次循环 进入下次循环
number = 9
while True:
guess = int(input("请输入一个数:"))
if guess == number:
print('====')
break
elif guess < number:
print('<<<<')
continue
else:
print('>>>>')
continue
for循环
# 一般在遍历 字典、列表的时候 可以确立循环次数的话使用for循环
#遍历列表
list = [1,2,3,4,5]
for item in list:
print(item)
#遍历字典
dict = {'name':'hhh','age':19}
for item in dict.values():
print(item)
# 嵌套循环
list =[[1,2,3],[4,5,6]]
for i in range(len(list)):
for j in range(len(list[i])):
print(list[i][j])