1 avilable_foods=["soup","beaf","noddle","pepper"] 2 request_foods=["soup","rice","beaf","suggar"] 3 for request_food in request_foods: 4 if request_food in avilable_foods: 5 print("adding "+request_food+".") 6 else: 7 print("sorry,we don't support for "+request_food+".") 8 print("finish your food.") 9 print("\n")10 11 customer_list=["lin","kakaxi","daitu","admin","sasik"]12 customer_list=[]13 if customer_list:14 for customer in customer_list:15 if customer =="admin":16 print("hello admin,welcome!")17 else:18 print("hello,"+customer+" thank you for logging")19 else:20 print("we need to find some users.")21 22 current_users=["jack","wang","robot","li","mole"]23 new_users=["zhao","mile","JACK","robot"]24 for new_user in new_users:25 if new_user.lower() in current_users:26 print("the name "+new_user+" is current occpuied")27 else:28 print("welcome to github!")29 print("\n")30 nums = [1,2,3,4,5,6,7,8,9]31 for num in nums:32 if num == 1:33 print("1st")34 elif num == 2:35 print("2nd")36 elif num == 3:37 print("3rd")38 else:39 print(str(num)+"th")
上述代码为Python中的列表访问练习代码,旨在领会Python中的for循环的便捷之处