顺序结构
- 代码重上到下,按照顺序执行
a = 5
b = a+ 1
c = b /2
# a:5 b:6 c:3
分支
- 分支结构 if…elif…else
a=8
b=5
c = 6
if a>b: // 判断条件
if a > c: // 判断条件
print(a)
eles:
print(c)
elif b > c: // 判断条件
print(b)
else:
print(c)
# 结果为8
循环
- while 循环
count = 1
sum = 0
while count < 11:
sum = sum + count
print(sum, count)
count = count + 1
# 返回
# 1, 1
# 3, 2
# 6, 3
# 10, 4
# 15, 5
# 21, 6
# 28, 7
# 36, 8
# 45, 9
# 55, 10
- for 循环
list1 = [1,2,3,4,5,6]
for i in list1:
print(i)
# 返回
# 1
# 2
# 3
# 4
# 5
# 6