Python 学习笔记(四)
Aug 25, 2016
用
in
和not in
检查特定值是否包含在列表中:1
2
3
4
5
6
7
8
9requested_toppings = ['mushrooms', 'onions', 'pineapple']
print('mushrooms' in requested_toppings) # True
print('pepperoni' in requested_toppings) # False
banned_users = ['andrew', 'carolina', 'david']
user = 'marie'
if user not in banned_users:
print(user.title() + ", you can post a response if you wish.")
下面这段程序
str()
是必须的:1
2
3
4
5
6
7
8
9age = 12
if age < 4:
price = 0
elif age < 18:
price = 5
else:
price = 10
print("Your admission cost is $" + str(price) + ".")