HiveBrain v1.2.0
Get Started
← Back to all entries
snippetpythonCritical

How do I check if a list is empty?

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
emptycheckhowlist

Problem

For example, if passed the following:

a = []


How do I check to see if a is empty?

Solution

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


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

Code Snippets

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

Context

Stack Overflow Q#53513, score: 7312

Revisions (0)

No revisions yet.