Sometimes, we want to check if a list is empty with Python.
In this article, we’ll look at how to check if a list is empty with Python.
How to check if a list is empty with Python?
To check if a list is empty with Python, we can use the not
operator.
For instance, we write:
a = []
if not a:
print("List is empty")
We put not
before a
to check if a
is empty.
Since this is True
, we see 'List is empty'
printed.
This works because empty lists are falsy.
Conclusion
To check if a list is empty with Python, we can use the not
operator.