“Python Enum” Code-Antworten

Python Enum

from enum import Enum
class Color(Enum):
    RED = 1
    GREEN = 2     
    BLUE = 3

"""
Color.RED
RED
1
Color.RED
"""
print(Color.RED)
print(Color.RED.name)
print(Color.RED.value)
print(Color["RED"])

val = "RED"
print(f"Value is {Color[val].value}")
Wojak's distant cousin

Python Enum

An enumeration is a set of symbolic names (members) bound to unique, constant values. Within an enumeration, the members can be compared by identity, and the enumeration itself can be iterated over.
Busy Batfish

Ähnliche Antworten wie “Python Enum”

Fragen ähnlich wie “Python Enum”

Weitere verwandte Antworten zu “Python Enum” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen