python中空列表判断方法总结,欢迎补充

--代码--

if __name__ == '__main__':
    l = []
    print(l.__len__() == 0)
    print(l.__sizeof__() == 40)
    print(len(l) == 0)
    print(l == [])
    print(l == list())
    print(l is not True)
    print(''.join(l) == '')  #这个不对,当list中全是空字符串时不适应
    print(l.__str__()=='[]')

 

--执行结果--

C:\Users\kusy\AppData\Local\Programs\Python\Python36\python.exe E:/wangjz/PyWorkSpace/LearnPython/checklist.py
True
True
True
True
True
True
True
True

Process finished with exit code 0

 

posted on 2018-08-21 11:35  一個未来  阅读(3932)  评论(0编辑  收藏  举报

导航