python判断list是否为空

判断list是否为空

  • 法1

    判断长度

    if len(mylist):
      # Do something with my list
    else:
      # The list is empty
    
  • 法2

    更简洁实用,空list等同于false,

    if mylist:
      # Do something with my list
    else:
      # The list is empty
    

引用链接

猜你喜欢

转载自blog.csdn.net/qq_24495287/article/details/83903655
今日推荐