# check if a list is empty python

33 views

## Problem:

Let’s say I have a list x = [] in python. How could I check this list is empty or not?

1 vote

## Solution:

There are several ways to check a list is empty or not in python. The most used and easy way is:

``````>>> x=[]
>>> if not x:
print ("This list is empty")
else:
print ("Yeah! you got it")``````

Another way is to use the if len(list)

``````def Enquiry(x):
if len(x) == 0:
return 0
else:
return 1

# Driver Code
x = []
if Enquiry(x):
print ("Yeah! you got it")
else:
print("This List is empty") ``````

I hope things are clear to you now. Keep digging.

## Related questions

5 views
Problem: How I can solve this issue : check if a list is empty python
11 views
Problem: HI KODLOGS: I want to understand how to check if list is eampty in python please explain in detail with examples. For example, if passed the following: a = [] How do I check to see if a is empty?
24 views
Problem: I am a new student in learning python and i am not sure how to check if a list is empty in python. For example, if the following is passed: a = [] How to check if it is empty?
11 views
Problem: How to I Solve this: python check if list is not empty HELP! I need help understanding this: python check if list is not empty Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
2 views
Problem: For example, if the following is approved: a = [] How can I check if it ais empty?
2 views
Problem: How to check if a number already exist in a list in python?
6 views
Problem: How to I Solve this: check if something is in a list python HELP! I need help understanding this: check if something is in a list python Can someone please help solve this, I am new in python(). Someone have idea to solve this thanks!
1 vote