博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python学习第四篇——列表访问与判定
阅读量:5060 次
发布时间:2019-06-12

本文共 1304 字,大约阅读时间需要 4 分钟。

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

转载于:https://www.cnblogs.com/shaonianpi/p/9463631.html

你可能感兴趣的文章
Primary definition
查看>>
第二阶段冲刺-01
查看>>
BZOJ1045 HAOI2008 糖果传递
查看>>
发送请求时params和data的区别
查看>>
JavaScript 克隆数组
查看>>
eggs
查看>>
一步步学习微软InfoPath2010和SP2010--第七章节--从SP列表和业务数据连接接收数据(4)--外部项目选取器和业务数据连接...
查看>>
如何增强你的SharePoint 团队网站首页
查看>>
FZU 1914 Funny Positive Sequence(线性算法)
查看>>
oracle 报错ORA-12514: TNS:listener does not currently know of service requested in connec
查看>>
基于grunt构建的前端集成开发环境
查看>>
MySQL服务读取参数文件my.cnf的规律研究探索
查看>>
java string(转)
查看>>
__all__有趣的属性
查看>>
BZOJ 5180 [Baltic2016]Cities(斯坦纳树)
查看>>
写博客
查看>>
利用循环播放dataurl的视频来防止锁屏:NoSleep.js
查看>>
python3 生成器与迭代器
查看>>
java编写提升性能的代码
查看>>
ios封装静态库技巧两则
查看>>