How do I check if a list is empty?

Ray picture Ray · Sep 10, 2008 · Viewed 3.2M times · Source

For example, if passed the following:

a = []

How do I check to see if a is empty?

Answer

Patrick picture Patrick · Sep 10, 2008
if not a:
  print("List is empty")

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