Question : Checking if a List Is Empty
Answered by : david-k
my_list = list()
# Check if a list is empty by its length
if len(my_list) == 0: pass # the list is empty
# Check if a list is empty by direct comparison (only works for lists)
if my_list == []: pass # the list is empty
# Check if a list is empty by its type flexibility **preferred method**
if not my_list: pass # the list is empty
Source : https://dev.to/renegadecoder94/71-python-code-snippets-for-everyday-problems-1mep | Last Update : Fri, 07 Oct 22
Question : How to check if a list is empty in python
Answered by : eric-tam
l = []
if len(l) == 0: print("the list is empty")
l = []
if l: print("the list is not empty")
else: print("the list is empty")
Source : | Last Update : Sun, 24 Jul 22