码迷,mamicode.com
首页 > 编程语言 > 详细

Python学习第四篇——列表访问与判定

时间:2018-08-12 18:45:40      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:new   customer   pre   for   python   学习   use   color   lower   

 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循环的便捷之处

Python学习第四篇——列表访问与判定

标签:new   customer   pre   for   python   学习   use   color   lower   

原文地址:https://www.cnblogs.com/shaonianpi/p/9463631.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!