python中if语句的运用

来源:互联网 发布:银龙裁决多少钱淘宝价 编辑:程序博客网 时间:2024/05/16 12:37
#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 = 12if age < 4:    print("too small")elif age > 18:    print("too big")else:    print("ok")#确定列表是否为空t = []if t:    print("列表不为空")else:    print("列表为空")
原创粉丝点击