xxxxxxxxxx
my_string = ""
if my_string == "":
print(True)
else:
print(False)
# Remember if you have even a white space in the string, the output will be - False.
xxxxxxxxxx
my_str = ""
if not my_str:
print("empty")
else:
print("not empty")
#output: empty
xxxxxxxxxx
# Method 1: using len() function
my_string = "Hello, World!"
if len(my_string) == 0:
print("String is empty")
else:
print("String is not empty")
# Method 2: using direct comparison
if my_string == "":
print("String is empty")
else:
print("String is not empty")
xxxxxxxxxx
string_var = "" # Replace "" with your string variable
if len(string_var) == 0:
print("The string is empty")
else:
print("The string is not empty")
xxxxxxxxxx
while True:
inp = input("TYPE IN HERE: ")
inp2 = inp.strip() # STRIP IT BABY
if len(inp2) < 1:
print("BLANK INPUT :(")
else:
print(inp) # PRINTING THE ORIGINAL (inp) VALUE