srccode srccode - 2 months ago 10
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

Try this:

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