python学习四

1.if的使用

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

for car in cars:
     if car == 'bmw':

     print(car.upper())

     else:

     print(car.title())

2.符号==,!=,>,<

3.要判断特定的值是否已包含在列表中,可使用关键字in 。

>>> requested_toppings = ['mushrooms', 'onions', 'pineapple'] 

>>> 'mushrooms' in requested_toppings

True
>>> 'pepperoni' in requested_toppings

False

4.不包含用not in

5.if-elif-else 结构

6.确定列表不是空的

requested_toppings = []

 if requested_toppings:
      for requested_topping in requested_toppings:

            print("Adding " + requested_topping + ".")

            print("\nFinished making your pizza!")

else:
     print("Are you sure you want a plain pizza?")

 

你可能感兴趣的:(python)