Python programmers typically check for empty lists by relying on truthiness.

Table of contents
Checking the length of a list
One way to check whether a list is empty is to check the length of that list.
If the length is 0
, the list must be empty:
>>> numbers=[]>>> iflen(numbers)==0:... print("The list is empty.")...The list is empty.
Or if we wanted to check for non-empty lists, we could make sure that the length is greater than 0
:
>>> iflen(numbers)>0:... print("The list is NOT empty.")...
But this is actually not the most typical way to check for an empty list in Python.
Evaluating the truthiness of a list
Many Python users prefer to …