How to check if a list is empty in Python?
Advertisements
In this tutorial we discuss the various ways of checking if a list is empty in Python.
len
lst = [1,2,3] if len(lst) == 0: print 'List Empty' else: print 'List not empty' #List not empty
Advertisements
bool
lst = [1,2,3] if not bool(list): print 'List Empty' else: print 'List not empty' #List not empty
Advertisements
equal
lst = [1,2,3] if lst == []: print 'List Empty' else: print 'List not empty' #List not empty