[Python] How do I test if int value exists in Python Enum without using try/catch?

Discussão em 'Python' iniciado por Stack, Maio 13, 2025.

  1. Stack

    Stack Membro Participativo

    Using the Python Enum class, is there a way to test if an Enum contains a specific int value without using try/catch?

    With the following class:

    from enum import Enum

    class Fruit(Enum):
    Apple = 4
    Orange = 5
    Pear = 6


    How can I test for the value 6 (returning true), or the value 7 (returning false)?

    Continue reading...

Compartilhe esta Página