enum.IntEnum in Python with Examples
Enum.IntEnum
In this tutorial, you are going to learn about the enum.intEnum in Python with Examples.
An enumeration is a set of unique and constant or fixed values.
Module Contents:
It defines four enumeration classes that can be used to define unique sets of names and values:
- Enum: It is a base class for creating enumerated constants.
- IntEnum: It is also a base class for creating enumerated constants and subclass of int.
- Flag: It is used to combine enumerated constants by bitwise operators.
- IntFlag: It is also a subclass of int and similar to a flag that is used to combine enumerated constants by bitwise operations.
IntEnum
It is used to compare Integers. See the Python code below:
from enum import IntEnum class Animals(IntEnum) Dog = 1 Cat = 2 Deer = 3 class WildAnimals(IntEnum) Lion = 1 Tiger = 2 Animals.Dog == 1 Animals.Dog == WildAnimals.Lion
Output: int.intenum Program Output.
from enum import IntEnum,Enum class Branch(IntEnum) ECE=1 CSE=2 EEE=3 Mech=4 Civil=5 class Degree(Enum) BTECH=1 BE=2 MBA=3 Branch.ECE=Degree.BTECH
Output: Int.enum and int.intenum Program and Output.
Here they still can’t be compared to Enum enumerations.
Explanation:
First of all import Enum and IntEnum
Create one class and create members with integers assigned to it.
Create another class that is inherited and create members with integers assigned to it.
Next compare both of them the result will be displayed according to that code.
We can compare intenum with intenum only.
Leave a Reply