我的视频学习笔记
for 循环:
range
range(start, stop[, step]) 左闭右开原则
for i in range(1, 9, 2):
print(i)
输出:
1
3
5
7
if 条件判断:
可以接受多个参数进行比较
x = 1
y = 2
z = 0
if x < y > z:
print("x is less than y, and y is greater than z")
输出:
x is less than y, and y is greater than z
if…elif…else 条件判断:
满足条件,即跳出if条件判断
x = -2
if x > 1:
print("x is greater than 1")
elif x < -1:
print("x is less than -1")
elif x < 1:
print("x is less than 1")
else:
print("x equal to 1")
print("finish running")
输出:
x is less than -1
finish running