python中if语句的运用

#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,python学习与开发)