Python – How to Check if a List is Empty

listpython

For example, if passed the following:

a = []

How do I check to see if a is empty?

Best Answer

if not a:
    print("List is empty")

Using the implicit booleanness of the empty list is quite Pythonic.

Related Question