user2118
0
Q:

check if list is empty python

>>> if len(a)==0:
    print ("list is empty")
else:
    print ("list is not empty")
1
if len(li) == 0:
    print('the list is empty')
2
if not a:
  print("List is empty")
1
if '' in list:
  # do stuff
0
For sequences, (strings, lists, tuples), use the fact that empty sequences are false.

Yes: if not seq:
     if seq:

No:  if len(seq):
     if not len(seq):
0
# An empty list object evaluates to False
a = []
not a
# Output:
# True
1

New to Communities?

Join the community