python判断列表为空

判断列表为空的方法

lists=[]
def listEmpty1(lists):
    if not lists:  return "列表为空"
def listEmpty2(lists):
    if len(lists)==0:  return "列表为空"
def listEmpty3(lists):
    if lists:  return "列表不为空"
    else:return "列表为空"
def listEmpty4(lists):
    try:
        lists[0]
    except Exception as e:
        print(e)
        return "列表为空"
def listEmpty5(lists):
    if lists is not None: return "列表为空"
print(listEmpty5(lists))

  

上班求生存,下班求发展
原文地址:https://www.cnblogs.com/ljf520hj/p/15218269.html