snippetpythonCritical
How do I check if a list is empty?
Viewed 0 times
emptycheckhowlist
Problem
For example, if passed the following:
How do I check to see if
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.