Assignment 4 =)
In this blog I will show you how to do this
- Write a Python program that checks if a list is empty or not.
- If the list is empty, print “Empty”. Else, print “Not Empty”.
For example, here is the expected out:
| List | Output |
|---|---|
| [] | “Empty” |
| [4] | “Not empty” |
| [4, 5, 6, 7] | “Not Empty” |
This is what I’m planning to do:
- Create a list
- Check the length of the list
- If the length of the list is 0 print empty, else print not empty.
Here is the code
toy_list = ["fhe"]
print(f"The length of toy_list is {len(toy_list)} so list is:", end=" ")
if len(toy_list) == 0:
print("Empty")
else:
print("Not empty")