I'm working with enum lately and I dont really get the utility of them in some cases. I hope my question is not too trivial or too stupid, and I would really love to better understand the logic behind this python structure. One common use I found online or in some pieces of code I have been working on lately is the use of values that are strings like for example:
from enum import Enum
class Days(Enum):
MONDAY = 'monday'
TUESDAY = 'tuesday'
...
SUNDAY = 'sunday'
And here from my humble prospective, the values seems redundant: if I print the values of some member I obtain the following:
print(Days.MONDAY.value)
>> 'monday'
I totally understand the utility when the values are numbers and they represent a gerarchic structure like for example
class Levels(Enum):
HIGH = 10
MID = 5
LOW = 0
In which you can do stuff like:
HIGH > LOW
> True
But in a lot of example and actual code use, I see the first approach, the one with MONDAY = 'monday', i.e. when the values are string instead of numerical values, and this case I really dont understand the utility of having a key that is pretty much equal to the value.
If anyone can help me understand, or show some utilities I would really love to understand new stuff.
Daysenum to instead useMON,TUE,WED, etc, without breaking any code that relies on the string values.