Irene
0
Q:

check if string is empty 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
2
my_str = ""
if not my_str:
  print("empty")
else:
  print("not empty")
#output: empty
4
if not myString:
3
# The least verbose answer is:
# if a is a data structure, then
# "not a" will evaluate to True if a is empty.

# This is a more explicit example
# for a deque data structure (could be any other data structure)
dq = deque()
empty_dq = deque()

dq.append(1) # dq now contains 1 element

if dq == empty_dq:
  print("Empty.")
else:
  print("Not empty.")
0

New to Communities?

Join the community