Types

Enums

Enum defines symbolic names for a fixed set of values.

An enum member has a symbolic name and an underlying value. The symbolic name is what readers usually care about in code.

Source

from enum import Enum

class Status(Enum):
    PENDING = "pending"
    DONE = "done"

current = Status.PENDING
print(current.name)
print(current.value)

Output

PENDING
pending
COLOR · CLOSED SETREDGREENBLUEno more
An enum names a fixed set of symbolic values; no new members appear at runtime.

Compare enum members with enum members, not with raw strings. This keeps the set of valid states explicit.

Source

print(current is Status.PENDING)
print(current == "pending")

Output

True
False

Notes

See also

Run the complete example

Example code

Expected output

PENDING
pending
True
False

Execution time appears here after you run the example.