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