2017.5.4 if_1

1. if语句

cars = ['audi','bmw','subaru','toyota']

for car in cars:

    if car == 'bmw':  #在python中都是用 : 来进入下一级

        print(car.upper())

    else:

        print(car.title())


car1 = 'audi'

print(car1 == 'Audi')  #python中会检查大小写

requested_topping = "mushroom"

if requested_topping != 'anchovies': #python中的不等于判断 以及不需要括号

    print("Hold the anchovies")

age_0 = 23

age_1 = 26

print(age_0>22 and age_1>22) #and 需要两个条件都满足 可添加括号

print(age_0<22 or age_1<22)  #or 只需要满足其中一个条件即可 可添加括号

是否在列表中,使用in

# in list or not

requested_toppings = ['mushroom','onions','pineapple']

a = 'mushroom' in requested_toppings

b = 'pepper' in requested_toppings

print(a)  #true

print(b)  #false

food = 'pepper'

if food not in requested_toppings:

print(food.title() + ' should also be added to the list')

你可能感兴趣的:(2017.5.4 if_1)