Member-only story

How to Check if a List Is Empty or Not in Python?

Python Checking if List Is Empty

Sanjay Priyadarshi
6 min readOct 11, 2022
Photo by Hitesh Choudhary on Unsplash

In Python, a list refers to a collection of data that is usually related to each other.

Instead of storing data in separate variables, we use a list to store it.

Let’s say we need to write a program where we need to store the total number of students in three different schools. Instead of using three different variables like studentsSchool1, studentsSchool2 and studentSchool3.

We can use one list to store the total number of students in the schools.

Like this:

studentsSchool = [400, 500, 600]

Several times when we write code using the python programming language, it is necessary to check if a list is empty or not.

Let’s find out how we can check if a list is empty in Python or not.

How to check if a list is empty in Python?

There are several ways to check if a list is empty or not.

To check if a list is empty or not, you can use the len() method and compare the length of an empty list using an if statement.

If you want, you can use the bool() function which would return False if an empty list is…

--

--

Sanjay Priyadarshi
Sanjay Priyadarshi

Written by Sanjay Priyadarshi

Join a Community of People Who Love Javascript, Programming and Technology — codertoentrepreneurs.substack.com

No responses yet