Getting value of enum on string conversion

I have the following enum defined:

from enum import Enum
class D(Enum):
    x = 1
    y = 2

print(D.x)

now the printed value is

D.x

instead, I wanted the enum’s value to be print

1

What can be done to achieve this functionality?

5 Answers
5

Leave a Comment