Skip to main content

What are Python descriptors and how are they used?

Mid Python
Quick Answer Descriptors implement __get__, __set__, __delete__ to control attribute access on a class. Used when an attribute needs validation or computation on access. @property is a built-in descriptor. Custom descriptors: class Validator: def __set__(self, obj, value): validate(value); obj.__dict__[name] = value. Used by SQLAlchemy and Django ORM to define column types and relationships.

Answer

Descriptors define __get__, __set__, and __delete__ methods.
Used for managing attribute access, validation, computed attributes, and reusable logic.
They power @property functionality in Python.
S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice