Answered by : vastemonde
my_list = list()
# Check if a list is empty by its length
if len(my_list) == 0: pass # the list is empty
# Check if a list is empty by direct comparison (only works for lists)
if my_list == []: pass # the list is empty
# Check if a list is empty by its type flexibility **preferred method**
if not my_list: pass # the list is empty
Source : | Last Update : Tue, 23 Feb 21
Answered by : dark-dingo-guly7c8q1t9h
a = []
if not a: print("List is empty")
Source : | Last Update : Wed, 18 Mar 20
Answered by : disturbed-dove-sm4l0b4imw0b
if len(li) == 0: print('the list is empty')
Source : https://stackoverflow.com/questions/53513/how-do-i-check-if-a-list-is-empty | Last Update : Mon, 17 Aug 20
Answered by : doubtful-dove
# Python program to declare
# empty list
# list is declared
a = []
Source : | Last Update : Mon, 02 Mar 20
Answered by : sam-z46isgk8vood
# For sequences, (strings, lists, tuples), use the fact that empty sequences are false:
# Correct:
if not seq:
if seq:
# Wrong:
if len(seq):
if not len(seq):
Source : https://stackoverflow.com/questions/53513/how-do-i-check-if-a-list-is-empty?rq=1 | Last Update : Fri, 08 Jul 22
Answered by : clumsy-chimpanzee-dnzkng8j7ccp
if not a: print("List is empty")
Source : https://stackoverflow.com/questions/53513/how-do-i-check-if-a-list-is-empty | Last Update : Sat, 09 Jan 21
Answered by : md-fuadul-islam-redoy
emptyList = [1]
length = len(emptyList)
if length == 0 and all(emptyList): print("This list is empty now.")
else: print("This list is not empty.\n\nThe values of list:") for x in emptyList: print(x)
Source : | Last Update : Sun, 22 May 22
Answered by : kvz
if not your_list: #List is empty
else: #List is not empty
Source : | Last Update : Thu, 07 Dec 23
Answered by : david-cao
l1 = ["Hire", "the", "top", "1%", "freelancers"]
l2 = []
if l2: print("list is not empty")
else: print("list is empty")
#Output: "list is empty"
Source : https://www.howtouselinux.com/post/check-python-list-is-empty | Last Update : Sun, 06 Mar 22
Answered by : eric-tam
l = []
if len(l) == 0: print("the list is empty")
l = []
if l: print("the list is not empty")
else: print("the list is empty")
Source : | Last Update : Sun, 24 Jul 22