Skip to main content
  1. Posts/

Assignment 4 =)

·111 words·1 min

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:

  1. Create a list
  2. Check the length of the list
  3. 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")