Python enum

whitehousechef·2025년 7월 7일

Enum

Name and value
for Example
REGULAR = "R", name is the left one which is REGULAR, and value is "R".

You can put multiple values for this value field cuz
Python's Enum has a special behavior:

When you assign a value to an enum member, it becomes the .value
If you define init, Python unpacks the value and passes it to init
So ("R", 10) gets unpacked as init(self, "R", 10)

class SeatType(Enum):
    REGULAR = ("R",10,".")
    PREMIUM = ("P",15,"$")
    VIP = ("V",20,"*")

    def __init__(self, short:str, price:int, symbol:str):
        self.short = short
        self.price = price
        self.symbol = symbol

0개의 댓글