創(chuàng)新互聯(lián)www.cdcxhl.cn八線動(dòng)態(tài)BGP香港云服務(wù)器提供商,新人活動(dòng)買多久送多久,劃算不套路!
小編給大家分享一下判斷python列表不為空的方法,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
python中判斷一個(gè)列表是否為空,可以使用以下方法
1、is not None 判斷
列表不為空
list_1 = [] if list_1 is not None: print('list is not none')
列表為空
list_1 = [] if list_1[0] is None: print('list_1 is none')
2.if 列表判斷
列表不為空(空列表等于 False)
list_2 = [] if list_2: print('list_2 is not none')
3.length列表長(zhǎng)度判斷
列表為空
list_3 = [] if len(list_3) == 0: print('list_3 is none')
list_3 = [] if len(list): print('list_3 is not none')
以上是判斷python列表不為空的方法的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道!