我在尝试使用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, 'King')
我该如何访问其中一个值,以便打印出13或'King'?
name
,因为它会与Enum.name
冲突。就像Rank.K.value
仍然存在一样,Rank.K.name
也是如此。 - Ramon Dias