상세 컨텐츠

본문 제목

Enums

Python

by techbard 2024. 12. 20. 15:38

본문

반응형
# Enums
# =====
# Key Features:
#   - Enums are iterable: You can loop through an Enum class.
#   - Unique values: Enum members are uniquel; two
#       members cannot have the same value.
#   - Immutable: Enum members are constants and cannot be modified.

from enum import Enum

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

red = Color.RED
green = Color.GREEN

print(red == Color.RED)
print(red == green)

print(Color.RED.name)
print(Color.RED.value)

for color_enums in Color:
    print(color_enums)

# Output:
True
False
RED
1
Color.RED
Color.GREEN
Color.BLUE
반응형

관련글 더보기

댓글 영역