avilable_foods=["soup","beaf","noddle","pepper"]
request_foods=["soup","rice","beaf","suggar"]
for request_food in request_foods:
if request_food in avilable_foods:
print("adding "+request_food+".")
else:
print("sorry,we don't support for "+request_food+".")
print("finish your food.")
print("\n") customer_list=["lin","kakaxi","daitu","admin","sasik"]
customer_list=[]
if customer_list:
for customer in customer_list:
if customer =="admin":
print("hello admin,welcome!")
else:
print("hello,"+customer+" thank you for logging")
else:
print("we need to find some users.") current_users=["jack","wang","robot","li","mole"]
new_users=["zhao","mile","JACK","robot"]
for new_user in new_users:
if new_user.lower() in current_users:
print("the name "+new_user+" is current occpuied")
else:
print("welcome to github!")
print("\n")
nums = [1,2,3,4,5,6,7,8,9]
for num in nums:
if num == 1:
print("1st")
elif num == 2:
print("2nd")
elif num == 3:
print("3rd")
else:
print(str(num)+"th")
上述代码为Python中的列表访问练习代码,旨在领会Python中的for循环的便捷之处