#encoding:utf-8
#if语句的运用
cars = ['audi', 'bmw', 'subaru', 'toyota']
for car in cars:
if car == 'bmw':
print(car.upper())
else:
print(car.title())
#检查特定值是否在列表中
temp = 'bmw'
if temp in cars:
print("temp in cars")
else:
print("temp not in cars")
# if-elif-else结构
age = 12
if age < 4:
print("too small")
elif age > 18:
print("too big")
else:
print("ok")
#确定列表是否为空
t = []
if t:
print("列表不为空")
else:
print("列表为空")
python中if语句的运用
最新推荐文章于 2025-07-30 10:40:17 发布
本文通过实例演示了Python中if语句的使用方法,包括基本的条件判断、elif-else结构的应用、检查列表中是否存在特定值及判断列表是否为空等核心内容。

3669

被折叠的 条评论
为什么被折叠?



