if empty in python code example

Example 1: check if string is empty python

my_str = ""
if not my_str:
  print("empty")
else:
  print("not empty")
#output: empty

Example 2: how to check empty string in python

my_empty_string = ''  # given the empty string a variable

def check_empty():
    if not my_empty_string: 
        print("Empty")
    else:
        print("Not Empty")


check_empty()



# by George Kwabena

Example 3: can python tell if a list is empty

>>> if len(a)==0:
    print ("list is empty")
else:
    print ("list is not empty")

Example 4: check if empty item in list python

if '' in list:
  # do stuff

Tags:

Java Example