Enum

Default Value for Enum

from enum import Enum

class MyEnum(Enum):
    HEADER = 'HEADER'
    BODY = 'BODY'
    UNKNOWN = 'UNKNOWN'
    
    @classmethod
    def _missing_(cls, value):
        return MyEnum.UNKNOWN

ΠŸΠΎΠ»ΡƒΡ‡Π΅Π½ΠΈΠ΅ значСния ΠΈ ΠΈΠΌΠ΅Π½ΠΈ:

from enum import Enum

class MyEnum(Enum):
    HEADER = 'Test'

MyEnum.HEADER.name == 'HEADER'
MyEnum.HEADER.value == 'Test'

Last updated