Posted on 28th April 2025|41 views
Could someone please tell me how can I represent an Enum in Python?
Posted on 28th April 2025| views
Here is one of the way to represent an Enum in Python:
class Enum(set):
def __getattr__(self, name):
if name in self:
return name raise AttributeError
Usage:
Animals = Enum(["elephant", "dog", "rat"])
print(Animals.elephant)