LoginSignup
1
0

More than 3 years have passed since last update.

PythonのEnumで0オリジンのインデックスを採番する

Posted at

背景

Pythonでは0falseに判断されてしまうことから、
通常のEnumでは1オリジンで採番されますが、
どうしても0オリジンにしたい場合の簡単な実装サンプルです。

環境

python: 3.7.7

実装サンプル

enum_0_origin.py
from enum import Enum

IDX = Enum('IDX', ['A', 'B', 'C'], start=0)
print(IDX.A.value)
# 0
print(IDX.B.value)
# 1
print(IDX.C.value)
# 2

以上、終わり。

1
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
1
0