Using the len() function we are able to empty the List. the lin() is a built-in function in Python that returns the length of an object. Lets look at the example below,
You can use the len() function to check if a list is empty. For example:
if not my_list:
# The list is empty
# The list is empty
Alternatively, you can use the len() function to check if a list is empty, like this:
if len(my_list) == 0:
# The list is empty
# The list is empty
You can also use the bool() function to check if a list is empty, like this:
if not bool(my_list):
# The list is empty
Comments (0)