0
0

Pythonの列挙型の個数、最大値、最小値の取得

Last updated at Posted at 2024-07-09

Pythonの列挙型(Enum)の個数、最大値、最小値の取得の仕方を備忘録として以下に示す。

enum.py
from enum import Enum, unique
@unique
class Position(Enum):
	SQUARE = 0
	SHORT  = 1
	LONG   = 2

@unique
class Action(Enum):
	WAIT      = 0
	SHORT     = 1
	LONG      = 2
	LIQUIDATE = 3

print(len(Action)) # 個数 4
print(max([e.value for e in Position])) # 最大値 2
print(min([e.value for e in Position])) # 最小値 0
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0