3.3Python语言的枚举(Enum)

枚举(Enum)是用来管理一组相关的有限个常量的集合,本质上是一种类。

class 枚举类名(enum.Enum):
    枚举常量列表
import enum


class WeekDays(enum.Enum):
    
    MONDAY = 1
    TUESDAY = 2
    WEDNESDAY = 3
    THURSDAY = 4
    FRIDAY = 10
day = WeekDays.FRIDAY
print(day)
print(day.name)
pring(day.value)
输出为:
WeekDays.FRIDAY
FRIDAY
10

原创文章,作者:huoxiaoqiang,如若转载,请注明出处:https://www.huoxiaoqiang.com/back/python/2734.html

发表评论

登录后才能评论