美文网首页
2018-07-27 Chapter 5 If

2018-07-27 Chapter 5 If

作者: 纤离 | 来源:发表于2018-07-27 17:35 被阅读0次

    If

    cars = ['audi', 'bmw', 'subaru', 'toyota']
    for car in cars:
    if car == 'bmw' :
    print(car.upper())
    else:
    print(car.title())

    > < >= <= () and or

    age1 = 21
    age2 = 65
    if age1 >= 18 and age1 < 30:
    print("age1 is " + str(age1) + ", so young people!")
    if (age2 < 12) or (age2 >= 60):
    print("age2 is " + str(age2) + ", child or old")

    In

    if ('audi' in cars):
    print("audi is in cars")
    if ('ddd' in cars):
    print("ddd is in cars")

    Not in

    if ('ddd' not in cars):
    print("ddd is't in cars")

    else & elif

    age1 = 15
    if age1 < 4:
    print("111")
    elif age1 < 10:
    print("222")
    elif age1 < 18:
    print("222")
    else:
    print("...")

    List is null

    list = []
    if list:
    for car in list:
    print(car.upper())
    else:
    print("list is null")

    ##############################

    Audi

    BMW

    Subaru

    Toyota

    age1 is 21, so young people!

    age2 is 65, child or old

    audi is in cars

    ddd is't in cars

    222

    list is null

    ##############################

    相关文章

      网友评论

          本文标题:2018-07-27 Chapter 5 If

          本文链接:https://www.haomeiwen.com/subject/aymgmftx.html