Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Check if list is empty in Python by comparing it with an empty list

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 empty')
    else:
        print('The list is not 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
Source by codinggear.blog #
 
PREVIOUS NEXT
Tagged: #Check #list #empty #Python #comparing #empty #list
ADD COMMENT
Topic
Name
3+1 =