我应该如何实现func
来正确返回Direction
枚举的相应值?
class Direction(Enum):
right = 0
down = 1
left = 2
up = 3
def func(self, n):
# When n = 0 return Direction.right
# When n = 1 return Direction.down
# When n = 2 return Direction.left
# When n = 3 return Direction.up
答案 0 :(得分:1)
不需要功能,可以像这样简单地完成:
>>> Direction(1)
<Direction.down: 1>
>>> Direction(3)
<Direction.up: 3>