Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Python by (10.2k points)
edited by

suppose I have passed : list=[]

How can I check if a list is empty or not?

2 Answers

0 votes
by (10.9k points)
edited by

@Anvi, following is an implicit way of checking if a list is empty or not:

if not list:

 print("empty list")

0 votes
by (106k points)
edited by

We have many ways to check whether a list is empty or not:-

The first way we can check is by using its length:-

abc_list = list()

if len(abc_list) == 0:

     print(“Empty list”)

image 

The second way we can check by direct comparison whether the list is empty:-

 abc_list = list()

 if abc_list==[]:

   print(“Empty list”)

   image

To know more about this you can have a look at the following video tutorial:-

Related questions

+1 vote
2 answers
+3 votes
2 answers
0 votes
1 answer
+2 votes
3 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...