2024-09-22 18:32:55 发布
网友
其目的是使用Enum类来允许对一定数量的选项进行可预测的输入
我希望得到整数作为输出,但是如果我打印它,我会得到class.attrib。 我怎样才能得到整数呢?提前谢谢
class Stiffness(Enum): FREE = 0 RIGID = 1 FLEXIBLE = 2 print(Stiffness.FLEXIBLE) #Output: Stiffness.FLEXIBLE #Expected output: 2
您可以使用^{}代替Enum
Enum
这允许Stiffness.FLEXIBLE与整数2互换使用,例如,您可以将其传递给需要整数的函数
Stiffness.FLEXIBLE
只需打印value:
value
print(Stiffness.FLEXIBLE.value) # 2
你可以看看the part of the enum documentation about attributes of enum members
您可以使用^{} 代替
Enum
这允许
Stiffness.FLEXIBLE
与整数2互换使用,例如,您可以将其传递给需要整数的函数只需打印
value
:你可以看看the part of the enum documentation about attributes of enum members
相关问题 更多 >
编程相关推荐