Example check if a list is empty in Python
Simple example code using most Pythonic way of checking the empty list. Since an empty list is False, the condition is false and hence we are able to identify an empty list.
l2 =  if l2: print("list is not empty") else: print("list is empty")
Another method is len() function
The len() function returns the length of the argument passed. If the length of the list is zero then the list is empty else not empty.
l2 = [1, 2, 3] if len(l2): print("the list is not empty") else: print("the list is empty")
Output: the list is not empty
Do comment if you have any questions or suggestions on this Python list topic.
Note: IDE: PyCharm 2021.1.3 (Community Edition)
All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.
Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology & like learning technical.