I have a small class which is as follows :
class Gender(object):
MALE = 'M'
FEMALE = 'F'
I have a parameter variable which can be only M or F.To ensure it is only that, I do the following :
>>> parameter = 'M'
>>> if parameter not in (Gender.MALE, Gender.FEMALE)
... print "Invalid parameter"
...
Invalid parameter
>>>
Now I have a class which contains all the States in USA as follows:
class States(object):
ALABAMA = 'AL'
ALASKA = 'AK'
ARIZONA = 'AZ'
ARKANSAS = 'AR'
CALIFORNIA = 'CA'
COLORADO = 'CO'
CONNECTICUT = 'CT'
DELAWARE = 'DE'
DISTRICTOFCOLUMBIA = 'DC'
....
....
Like the example above,my parameter now is AL.However, since there are 50 states in the USA,I cannot practically use the tuple with 50 variables like I used above.Is there a better way of doing this ? I did read about isinstance but it did not give me the expected results.