Replace Magic Strings with Enum

Talk it through out loud with your AI coach.

The problem

  • medium
  • Pro

An order system passes statuses around as strings like pending, shipped and cancelled, and a typo of shipped went unnoticed for weeks. Explain how Python's enum module would help, and what to watch for when statuses are saved to and loaded from a database.

What a strong answer covers

  • Why free-form strings let mistakes slip through.
  • What an enum gives you over plain constants.
  • Moving between enum members and the values you store.
  • A comparison surprise to watch for when mixing members and raw values.

Common mistake: Comparing an enum member directly with the string from the database and assuming it matches.

Knowing this is half of it. Saying it clearly out loud is the part the coach helps you practise.

Practise it out loud