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

Posted 少年π

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python学习第四篇——列表访问与判定相关的知识,希望对你有一定的参考价值。

 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("
")
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("
")
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学习第四篇——列表访问与判定的主要内容,如果未能解决你的问题,请参考以下文章

python学习之第四篇:Python中的列表及其所具有的方法

python学习第四篇python函数

21天学习挑战赛Python学习第四篇:多线程 threading 模块

21天学习挑战赛Python学习第四篇:多线程 threading 模块

第四篇编码与解码及列表元祖

python学习第四篇python函数