所以我试图在python中使用枚举,并遇到以下错误:
当我使用枚举作为元组并给它两个值时,我无法仅访问一个值,例如tuple[0]
class Rank(Enum):
ACE = 1
TWO = 2
THREE = 3
FOUR = 4
FIVE = 5
SIX = 6
SEVEN = 7
EIGHT = 8
NINE = 9
TEN = 10
JACK = 11
QUEEN = 12
KING = 13, "King"
print (Rank.KING.value)
和打印是
(13,“国王”)
如何只访问一个值,以便打印13或“King”?
最佳答案
您可以通过以下方式访问13或“king”:
Rank.KING.value[0]
Rank.KING.value[1]
关于python - python元组和枚举,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54793033/