Chemi Chemi - 1 year ago 379
Python Question

Python: Shorter way of checking if a string equals two other strings

have just started learning python and this question came up to my mind
is there a shorter way to determine if a string equals 'something' or 'somethingelse'?


input = raw_input("question?")

while input != 'n' and input != 'y':
#ask question again

Answer Source

You could check whether it is in a list or set.

input = raw_input("question?")

while input not in ['n', 'N']:
    #ask question again

If you are just trying to accept two cases though, you could also just call lower on the input.

while input.lower() != 'n':
    #ask question again
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download