1. cars = ['audi', 'subaru', 'bmw','toyota']
    2. for car in cars:
    3. if car == 'bmw':
    4. print(car.upper())
    5. else:
    6. print(car.title())

    Python在条件判断时大小写敏感

    1. a = 'H'
    2. a == h # False

    不等 !=
    逻辑与 and
    逻辑或 or
    判断一个值是否在list里 in
    判断一个值是否在list里 not in
    布尔值首字母大写 True False

    if - elif -else

    1. age = 4
    2. if age < 4:
    3. print("Your admission cost is $0.")
    4. elif age < 18:
    5. print("Your admission cost is $25.")
    6. else:
    7. print("Your admission cost is $40.")

    在Python中,最后的else判断不是必须的

    判断list是否为空

    1. requested_toppings = []
    2. if requested_toppings:
    3. print('Y')
    4. else:
    5. print('N')

    代码风格:
    运算符两边要有空格

    1. if a == 4: