from enum import Enum #所有枚举类是Enum类的子类 # Yellow:黄钻 Green:绿钻 Black:黑钻 Red :红钻 class VIP(Enum): Yellow=1 Green=2 Black=3 Red=4 # print(VIP.Yellow) # yellow=1 # green=2 # {'yellow':1,'greeen':2} # # class TypeDiamond(): # yellow=1 # green=2 #缺陷:可变 没有防止相同值的功能 class Common(): YELLOW=1 a=1 print(VIP(a)) # print(type(VIP.Green.name)) # print(type(VIP.Green)) # <class 'str'> # <enum 'VIP'> #枚举类型 枚举值 枚举的名字 # for v in VIP: # print(v) # VIP.Yellow # VIP.Green # VIP.Black # VIP.Red
python
最新推荐文章于 2023-09-16 01:18:17 发布