Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Check if list is empty in Python Using the len() method

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 len(lst) == 0:
        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 #Using #method
ADD COMMENT
Topic
Name
7+1 =