Python中的枚举数据类型(Enum)_python enum-CSDN博客
默认属性name和value
from enum import Enum class Weekday(Enum): monday = 1 tuesday = 2 wednesday = 3 thirsday = 4 friday = 5 saturday = 6 sunday = 7 print(Weekday.wednesday) # Weekday.wednesday print(type(Weekday.wednesday)) # <enum 'Weekday'> print(Weekday.wednesday.name) # wednesday print(Weekday.wednesday.value) # 3
自定义属性
from enum import Enum class Weekday(Enum): monday = 1 tuesday = 2 wednesday = 3 thirsday = 4 friday = 5 saturday = 6 sunday = 7 Weekday.wednesday.label = "星期三" Weekday.wednesday.work = "完成假期作业" Weekday.wednesday.time = 10 print(Weekday.wednesday.label) # 星期三 print(Weekday.wednesday.work) # 完成假期作业 print(Weekday.wednesday.time) # 10
标签:enum,Python,Enum,wednesday,枚举,Weekday,print From: https://www.cnblogs.com/daizichuan/p/18458599