Saturday 11 September 2021

Python: What is the type of enumeration member

Type of enumeration member is the enumeration it belongs to.

 

typeOfEnumeration.py

from enum import Enum

class Day(Enum):
    MONDAY = 1
    TUESDAY = 2
    WEDNESDAY = 3
    THURSDAY = 4
    FRIDAY = 5
    SATURDAY = 6
    SUNDAY = 7

print('enum_member \t\t type')
for day in Day:
    print(day, "\t->\t", type(day))

 

Output

enum_member              type
Day.MONDAY      ->       <enum 'Day'>
Day.TUESDAY     ->       <enum 'Day'>
Day.WEDNESDAY   ->       <enum 'Day'>
Day.THURSDAY    ->       <enum 'Day'>
Day.FRIDAY      ->       <enum 'Day'>
Day.SATURDAY    ->       <enum 'Day'>
Day.SUNDAY      ->       <enum 'Day'>

 

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment