Difference between Enum and IntEnum in Python

From the python Docs:

Enum: Base class for creating enumerated constants.

and:

IntEnum: Base class for creating enumerated constants that are also subclasses of int.

it says that members of an IntEnum can be compared to integers; by extension, integer enumerations of different types can also be compared to each other.

look at the below example:

class Shape(IntEnum):
    CIRCLE = 1
    SQUARE = 2

class Color(Enum):
    RED = 1
    GREEN = 2

Shape.CIRCLE == Color.RED
>> False

Shape.CIRCLE == 1
>>True

and they will behave same as an integer:

['a', 'b', 'c'][Shape.CIRCLE]
>> 'b'

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)