Enum type

Enum (enumeration) is a custom data type (a data type that can define its type). We can determine what it contains. When defining it, we give a set of values of this type (similarly, e.g., an int has a set of allowed values - a range).


from enum import Enum

class Day(Enum):
    Mo = "Monday"
    Tu = "Tuesday"
    We = "Wednesday"
    Th = "Thursday"
    Fr = "Friday"
    Sa = "Saturday"
    Su = "Sunday"

print(Day.Tu.value)

def get_day(x: Day) -> str:
    return x.value

today = Day.Mo
print(get_day(today))
                                    


from enum import Enum, auto

class Color(Enum):
    RED = auto() # automatically assigning increasing integer values (starting from 1) to the members of an Enum class
    GREEN = auto()
    BLUE = auto()

print(Color.RED.value) # 1
print(Color.GREEN.value) # 2
print(Color.BLUE.value) # 3