- Before Python 3.4 (PEP 435),
or
class Animal:
DOG = 1
CAT = 2
x = Animal.DOG
class Animal:
DOG, CAT = range(2)
x = Animal.DOG - Since Python 3.4 (PEP 435),
or equivalently:
class Animal(Enum):
DOG = 1
CAT = 2
x = Animal.DOG
from enum import Enum
Animal = Enum('Animal', 'DOG CAT')
x = Animal.DOG
No comments:
Post a Comment