2021-10-28发表2021-10-28更新开发总结几秒读完 (大约84个字)Python3-enum枚举类使用示例12345678910111213141516171819202122232425262728from enum import Enum# 声明枚举类class Branch(Enum): MAIN = "main branch" DEV = "develop branch"print(Branch.MAIN.name) # MAINprint(Branch.MAIN.value) # main branchprint(Branch["MAIN"]) # Branch.MAINprint(Branch("main branch")) # Branch.MAINprint(Branch.MAIN) # Branch.MAINprint(Branch.MAIN == Branch.MAIN) # Trueprint(Branch.MAIN == Branch.DEV) # Falseprint(Branch.MAIN is Branch.MAIN) # Truefor branch in Branch: print(branch) # Branch.MAIN # Branch.DEVfor branch in Branch.__members__: print(branch) # MAIN # DEVPython3-enum枚举类使用示例https://wyue1227.github.io/2021/10/28/开发总结/Python3-enum枚举类使用示例/作者Etsu发布于2021-10-28更新于2021-10-28许可协议#代码段Python