0 votes
2 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 (107k 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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...