xxxxxxxxxx
code
# empty list & non-empty list
empty_list = []
non_empty_list = [1, 2, 3, 4]
# check if list is empty
def check_list_empty(lst):
if lst:
print('The List is not empty')
else:
print('The list is empty')
# pass in the lists to check_list_empty
check_list_empty(empty_list)
check_list_empty(non_empty_list)
# Output
The list is empty
The List is not empty
xxxxxxxxxx
code
# empty list & non-empty list
empty_list = []
non_empty_list = [1, 2, 3, 4]
# check if list is empty
def check_list_empty(lst):
if bool(lst): #changed here
print('The List is not empty')
else:
print('The list is empty')
# pass in the lists to check_list_empty
check_list_empty(empty_list)
check_list_empty(non_empty_list)
#Output
The list is empty
The List is not empty