目录
for循环中使用if语句
arr = ["A", "B", "C"]
for item in arr:
print(item)
print("--------------")
# 等于
for item in arr:
if item == "A":
print(item, "arr 中有 A")
print("=============")
# 不等于
for item in arr:
if item != "F":
print(item, "不是 F")
if in、if no in
arr = ["A", "B", "C"]
# 列表存在判断
if "A" in arr:
print("arr 中有 A")
if "M" not in arr:
print("arr 中没有 M")
多条件判断:if or、if and
# 多个条件判断
a = 5
b = 3
if a == 5 or b > 6:
print("a == 5 or b > 6")
if a > 0 and a != 1 and b < 6:
print("a > 0 and a != 1 and b < 6")
if-else
score = 75
# if-else
if score < 60:
print("不及格")
else:
print("及格")
if-elif-else
score = 75
# if-else
if score < 60:
print("不及格")
elif score >= 60 and score < 90:
print("良好")
else:
print("优秀")
if-elif-elif-else
score = 98
# if-else
if score < 60:
print("不及格")
elif score >= 60 and score < 90:
print("良好")
elif score > 90 and score < 95:
print("优秀")
else:
print("非常优秀")