Python3入门与进阶——枚举留神关键点。
from enum import Enum class Vip(Enum): GREEN=1 YELLOW=2 PURPLE=3 print(type(GREEN))#报错 print(type(Vip.GREEN))# print(type(Vip.GREEN.name))# print(type(Vip.GREEN.value))# print(GREEN)#b报错 print(Vip.GREEN)#Vip.GREEN(返回的是枚举类型) print(Vip['GREEN'])#Vip.GREEN(同上) print(Vip.GREEN.name)#GREEN(打印枚举的名字)(返回
用户评论