python从入门到实践-5章if语句
#!/user/bin/env python
cars = ['audi','bmw','subaru','toyota']
for car in cars:
if car == 'bmw':
print(car.upper())
else:
print(car.title())
# == !=
# <= >=
# and or
# in not in
# True False
# if-else
# if-elif-elif-else # 选择一个执行
requesed_toppings = ['mushrooms','green peppers','extra cheese']
for requesed_topping in requesed_toppings:
if requesed_topping == 'green peppers':
print("Sorry,we are out of green peppers now.")
else:
print("Addin" + requesed_topping + ".")
print('\nFinished making your pizza!')
# 确定列表不是空
requesed_toppings = []
if requesed_toppings:
for requesed_topping in requesed_toppings:
print("Adding" + requesed_topping + ".")
print("\nFinished making your pizza!")
else:
print("Are you sure you want a plain pizza?")
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步