Checking if input box is empty using Python

I just wanted to ask how can we check if the value of an input box is empty using Python, on the image below, I wanted to check the input box if empty and print some values if the statement is true also if it is false. Currently it is error because of the value (note that I did not put any value as indicated in the image with boxed red).

enter image description here

Upvotes: 0

Views: 2312

Answers (3)

NameError
NameError

Reputation: 260

I guess I am little late, but I'll try to help.

You can use the isspace() and "" (empty string).

if isspace(pashu) == True or pashu == "":
    print("This is empty")
else:
    print("continue")

Did this help?

Upvotes: 0

ToTamire
ToTamire

Reputation: 1703

Expression:

bool('')

Returns False. Expression:

bool('a')

Returns True. Thats mean you can check if string is empty by conversion to bool. if statement does is automatically.

if pashu:
    print('this is empty')

Upvotes: 0

Nico Müller
Nico Müller

Reputation: 1874

You have to evaluate if the value attribute is an empty string

if pashu == "":

Upvotes: 2

Related Questions