# 6.1. OOP Enum

## 6.1.1. Rationale

• List of finite choices

• Enumerations

## 6.1.2. Definition

Listing 269. Defining enum
from enum import Enum

class Color(Enum):
RED = '#00FF00'
GREEN = '#00FF00'
BLUE = '#0000FF'

my_color = Color.RED

Listing 270. Defining enum
from enum import Enum

class Status(Enum):
ALIVE = 'alive'


## 6.1.3. Accessing names and values

Listing 271. Accessing names and values
from enum import Enum

class Color(Enum):
RED = '#00FF00'
GREEN = '#00FF00'
BLUE = '#0000FF'

print(Color.RED)        # Color.RED
print(Color.RED.name)   # RED
print(Color.RED.value)  # '#00FF00'


## 6.1.4. Iterating over Enum

Listing 272. Iterating over Enum
from enum import Enum

class Color(Enum):
RED = '#00FF00'
GREEN = '#00FF00'
BLUE = '#0000FF'

for color in Color:
print(color)

# Color.RED
# Color.GREEN
# Color.BLUE


## 6.1.5. Identity check

Listing 273. Identity check
my_color = Color('#00FF00')     # <Color.GREEN: '#00FF00'>
my_color is Color.RED           # False
my_color is Color.GREEN         # True


## 6.1.6. Use cases

Listing 274. enum - Example usage
from enum import Enum

class Permission(Enum):
WRITE_EXECUTE = 0b011
WRITE = 0b010
EXECUTE = 0b001
NONE = 0b000

Listing 275. enum - Example usage
from enum import IntEnum

class IndexDrives(IntEnum):
""" This enum holds the index value of drive object entrys
"""
ControlWord = 0x6040
StatusWord = 0x6041
OperationMode = 0x6060


## 6.1.7. Assignments

Todo

Create assignments