python中判断列表是否为空


一、

>>> test1 = ["ccc","ddd","mmm"] >>> if test1: for i in test1: print(i) else: print("empty list") ccc ddd mmm >>> test1 = [] >>> if test1: for i in test1: print(i) else: print("empty list") empty list

 

二、

>>> test1 = ["ccc","eee","kkk"] >>> lenlist=len(test1) >>> if lenlist != 0: for i in test1: print(i) else: print("empty list") ccc eee kkk >>> test1 = [] >>> lenlist=len(test1) >>> if lenlist != 0: for i in test1: print(i) else: print("empty list") empty list

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM