3 ms·
There are many advantages. Here are some: >>> class MyEnum(Enum): ... VALUE_ONE, VALUE_TWO, VALUE_THREE = range(3) ... >>> v = MyEnum.VALUE_ONE >>
by eliben 13y ago
There are many advantages. Here are some:
>>> class MyEnum(Enum):
... VALUE_ONE, VALUE_TWO, VALUE_THREE = range(3)
...
>>> v = MyEnum.VALUE_ONE
>>> v == 0
False
>>> v == MyEnum.VALUE_ONE
True
>>> type(v)
<enum 'MyEnum'>
>>> isinstance(v, MyEnum)
True
>>> print(v)
MyEnum.VALUE_ONE
>>>
Now try to think how these would result if you'd defined VALUE_ONE... your way.