Halo
发布于 2024-10-29 / 43 阅读 / 0 评论 / 0 点赞

枚举

from enum import Enum # pip install enum34
class Build(Enum):
    debug = 200
    build = 400
  1. string to enum
    a=Build['debug']
    output: '400'

  2. enum to string
    a.name
    output: 'debug'

  3. .int to enum
    b=Build(400)

  4. enum to int
    b.value


评论