How do I check if input has been entered?
For example (python2)
x = str(raw_input('Message>> '))
or
(python3)
y = input('Number>> ')
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You know if nothing was entered for the second one because it will raise a
SyntaxError. You can catch the error like this:then test
or, preferably, use
raw_input:For the first one,
xwill be an empty string if nothing is entered. The call tostris unnecessary —raw_inputalready returns a string. Empty strings can be tested for explicitly:or implicitly:
because the only
Falsestring is an empty string.