0
if b(list) = 0;
    print('empty');

I want to make it to find out if the list is empty but this not working, I am too new for this. what can I do if I want to know if the list is empty?

saloua
  • 2,433
  • 4
  • 27
  • 37
OoKkAaYy
  • 3
  • 2
  • try ```if len(list)==0: print("List is empty.")``` –  May 14 '21 at 10:05
  • Yes, the semicolon does not belong in python. – C. Peck May 14 '21 at 10:26
  • I recommend looking for existing answers to your question in TackOverflow before posting the question. This a duplicate of the following question https://stackoverflow.com/questions/53513/how-do-i-check-if-a-list-is-empty Also the mentioned code syntax is not correct. For example, to check a coding in `if statement` you must use `==` and not `=` – saloua May 14 '21 at 16:04
  • Does this answer your question? [How do I check if a list is empty?](https://stackoverflow.com/questions/53513/how-do-i-check-if-a-list-is-empty) – GuedesBF May 15 '21 at 00:48

2 Answers2

0

Here

list_test=[]
if list_test==[]:  #== Since an empty list is potrayed as [], it check if the list is []
    print("List is empty.")
else:
    print("List is not empty.")
  • Answer's are great. But please add some text around your code to help the OP understand your answer. This encourages them not to copy/paste the answer. Thank you! – Buddy Bob May 14 '21 at 16:26
0

To check if a list is empty you can use a if check. I am assuming that your empty list is called empty_list

empty_list = []
if not empty_list:
    print('list is empty')
else:
    print('List contains data')
Uber
  • 331
  • 1
  • 5
  • 18