How do I check if a list is empty?

To check if a list is empty in Python, you can use an if statement and the len() function.

Here's an example:

my_list = []
if not my_list:
    print("The list is empty")

This will print "The list is empty" if my_list is an empty list.

Watch a course Python - The Practical Guide

You can also use the len() function to check if the list is empty, like this:

my_list = []
if len(my_list) == 0:
    print("The list is empty")

Both of these approaches will work for any iterable, not just lists.