Check if a list is empty in Python


Check if a list is empty in Python

#create empty list
a = []
#empty list will return a boolean false
if not a:
print("List is empty")
List is empty
#if we want to check explicitly
if len(a) == 0:
print('List is empty')
List is empty


Ace your next data science interview

Get better at data science interviews by solving a few questions per week



Find a bug? Submit a suggested change on Github, or message me on Twitter.