#字符串比较,处理列表
# 将列表作为条件表达式时,列表为空时返回False
print(f"字符串比较:")
names = ['li','ma','yang','cai']
for name in names:
if name == 'ma':
print(name.upper()) #不会改变原始的值
elif name == 'yang':
print(name.lower()) #不会改变原始的值
else:
print(name.title()) #不会改变原始的值
#验证没有改变原始的值
print(names)
if 'ma' in names:
print("True")
else:
print("False")
if 'zhang' not in names:
print("True")
#数值比较,if-elif-elif
print(f"\n数值比较:")
answer = 17
if answer !=42:
print("That is not the correct answer.Please try again!")
elif answer == 17:
print("That is the correct answer!")
elif answer > 17 :
print("That is less than the answer!")
#检查多个条件,if-elif-else
print(f"检查多个条件:")
number = int(input("请输入成绩:"))
if (numbe
Python if条件语句
最新推荐文章于 2024-08-27 09:41:07 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)