Descriptors

Talk it through out loud with your AI coach.

The problem

  • hard
  • Pro

Several of your classes have numeric fields that must never be negative, and copying the same property into every class is getting repetitive. An interviewer suggests a descriptor. Explain what descriptors are, how Python's attribute lookup uses them, and how you'd build a reusable non-negative field.

What a strong answer covers

  • What makes an object a descriptor and where it lives.
  • How descriptors fit into the order Python looks up attributes.
  • Building a reusable validated field.
  • Everyday Python features that work this way.

Common mistake: Storing the value on the descriptor itself, so every instance of the class ends up sharing one value.

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

Practise it out loud