banned_users =['andrew','carolina','david']
user ='marie'if user notin banned_users:print(user.title()+", you can post a response if you wish.")
if-else语句
age =18if age >=18:print("You are old enough to vote!")else:print("Sorry, you are too young to vote.")
if-elif-else语句
age =12if age <4:print("Your admission cost is $0.")elif age <18:print("Your admission cost is $5.")else:print("Your admission cost is $10.")
确定列表不是空的
requested_toppings =[]if requested_toppings:for requested_topping in requested_toppings:print("Adding "+ requested_topping +".")print("\n Finished making your pizza!")else:print("Are you sure you want a plain pizza?")
使用多个列表
available_toppings =['mushrooms','olives','green peppers','pepperoni''pineapple','extra cheese']
requested_toppings =['mushrooms','french fries','extra cheese']for requested_topping in requested_toppings:if requested_topping in available_toppings:print("Adding "+ requested_topping +".")else:print("Sorry, we don't have "+ requested_topping +".")
1、if语句的本质每条if语句都是一个条件测试的表达式,其值为True或者False。2、简单使用cars = ['audi', 'bmw', 'subaru', 'toyota']for car in cars: if car == 'bmw': print(car.upper()) else: print(car.title())3、一些特性和使用区分大小写...