Python - check if a list is empty ?
To check if a list is empty or not we simple put the list variable inside if condition. If the list is not empty it will be treated as true and code inside if block will be executed, otherwise code inside if block will not be executed.
myList = [] # This is a empty list
if myList:
# since myList is empty this not be executed.
print("List is not empty")
else:
print("List is empty")
Executing if block only if list is empty can be done using not operator before list.
newList = []
if not newList:
print("list is not empty")