Skip to content

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.