Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesSenior Deep-DivesModule 10 · Production idioms (modern Python)enum.StrEnum — type-safe strings that serialise like stringspredict145 / 161
+150 XP
Task
📝 **Task:** Predict the 9-line output. A StrEnum 'Status' has 3 members. The lesson exercises: print(member) gives the VALUE not the qualified name (the StrEnum surprise); == comparison with plain string is True; isinstance(member, str) is True; f-string interpolation prints the value; lookup-by-value works and lookup-by-name accessor works; invalid lookup raises ValueError; iteration follows declaration order. 📋 Implement the function above. Tests run automatically. 💡 **Hint:** Re-read the theory if you get stuck.
Predict the output

Read the code carefully

from enum import StrEnum


class Status(StrEnum):
    PENDING = "pending"
    ACTIVE = "active"
    CANCELLED = "cancelled"


s = Status.ACTIVE

# 1. print(member) — the StrEnum surprise: value, NOT Status.ACTIVE
print(s)
# 2. Equal to the plain string
print(s == "active")
# 3. .value accessor (same as print here, but explicit)
print(s.value)
# 4. isinstance(member, str) — StrEnum members ARE strings
print(isinstance(s, str))
# 5. f-string interpolation uses str(member) = the value
print(f"status: {s}")

# 6. Lookup by value — print(member) again returns value
print(Status("pending"))
# 7. .name accessor — capital identifier
print(Status("pending").name)

# 8. Invalid value
try:
    Status("nope")
except ValueError:
    print("invalid value")

# 9. Iteration order = declaration order
print([m.value for m in Status])

What will the program print? Write here:

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…