Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何在Python 3中枚举常量_Python 3.x_Constants_Enumeration - Fatal编程技术网

Python 3.x 如何在Python 3中枚举常量

Python 3.x 如何在Python 3中枚举常量,python-3.x,constants,enumeration,Python 3.x,Constants,Enumeration,我想要一个简单的表单来定义多个常量并对它们进行枚举,这样只使用每个常量的名称就可以得到枚举的值,类似于C中的enum,但在Python3中。例如: harmonic=0 vrms=1 irms=2 . . . and so 欢迎来到stackoverflow!请尽量更准确地回答你的问题,这最终会帮助所有人,也使你的问题更有可能得到回答。祝你一切顺利,安德烈亚斯 >>> from enum import Enum >>> class mycons(Enum)

我想要一个简单的表单来定义多个常量并对它们进行枚举,这样只使用每个常量的名称就可以得到枚举的值,类似于C中的enum,但在Python3中。例如:

harmonic=0
vrms=1
irms=2
.
.
.
and so


欢迎来到stackoverflow!请尽量更准确地回答你的问题,这最终会帮助所有人,也使你的问题更有可能得到回答。祝你一切顺利,安德烈亚斯
>>> from enum import Enum
>>> class mycons(Enum):
...  vrms=1
...  irms=2
...  

>>> print(mycons.irms.name)
irms
>>> print(mycons.irms.value)
2