my_list = list()
# Check if a list is empty by its length
if len(my_list) == 0:
pass # the list is empty
# Check if a list is empty by direct comparison (only works for lists)
if my_list == []:
pass # the list is empty
# Check if a list is empty by its type flexibility **preferred method**
if not my_list:
pass # the list is empty
list2 = filter(None, list1)
if __name__ == '__main__':
n = 10
a = [[] for x in range(n)]
print(a) # [[], [], [], [], [], [], [], [], [], []]
# Python program to declare
# empty list
# list is declared
a = []
list = list()
list = []
if not a:
print("List is empty")
# There are two common methods to create an empty list
x = list()
print(len(x)) # Output: 0
y = []
print(len(x)) # Output: 0
# Python program to declare
# empty list
# list is declared
a = []
print("Values of a:", a)
print("Type of a:", type(a))
print("Size of a:", len(a))
l_empty = []
print(l_empty)
# []
print(len(l_empty))
# 0
>>> num = []
>>> len(num)
0