srccode srccode - 1 year ago 58
Python Question

Simplify python code- iterative compare in if

I want to simplify this statement in python.

if string=='M' or string=='m' or string=='Male':
print "OK"

Answer Source

Try this:

if string in ["M", "m", "Male"]:
    print "OK"