How to check if a list is empty in python

How to check if a list is empty,in this topic you will learn verifying list is empty or not in python language with the help of simple code.

Below is the code:

a=[];

I'm checking a is empty or not using for loop as below

if not a:
  print("List is empty")


OR


 a = []
 try:
  print(a[-1])
 except IndexError:
  print("List is empty")

No comments:

Post a Comment