Search code examples
pythonenumstuples

python tuple and enum


So I was trying to use enums in python and came upon the following error: When I was using enum as a tuple and giving it two values, I can't access only one value such as 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)

and the print is

(13, 'King')

How can I access only one value so I can print 13 or 'King'?


Solution

  • You have the following possibilites to access 13 or "king":

    Rank.KING.value[0]
    Rank.KING.value[1]