python判断list是否为空
判断一个 list 是否为空
传统的方式:
1if len(mylist):
2 # Do something with my list
3else:
4 # The list is empty
由于一个空 list 本身等同于 False,所以可以直接:
1if mylist:
2 # Do something with my list
3else:
4 # The list is empty
捐赠本站(Donate)
如您感觉文章有用,可扫码捐赠本站!(If the article useful, you can scan the QR code to donate))
- Author: shisekong
- Link: https://blog.361way.com/python-list-is-null/4019.html
- License: This work is under a 知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. Kindly fulfill the requirements of the aforementioned License when adapting or creating a derivative of this work.