Ctrl K
Python · Senior · Theory

Walk me through how Python looks up an attribute when you access obj.attr. Where do descriptors fit into this, and why does property work the way it does?

~4 min by voice

How to approach it

The interviewer checks whether the candidate understands the actual algorithm of object.__getattribute__ and the priorities of data/non-data descriptors relative to the instance __dict__, and whether they can use that to explain property, bound methods, cached_property and __getattr__, rather than just saying "first the object, then the class".

Have you seen this question in a real interview?
Answers0
Avg. score—
Strong—
Practiced0
Topics
Similar questionsA service has a function def add_tag(tag, tags=[]), and after a few calls, the results start containing tags that belong to other calls. What's going on, and how do you fix it? Mid-levelWhat happens when you override __eq__ in your class, and how does that relate to __hash__? How would you make an object that can safely be put in a set and used as a dictionary key? SeniorWhat's the difference between a shallow copy and a deep copy in Python? When does that difference matter? JuniorYou overrode __eq__ on a Money class, and when you tried to put an object in a set, you got TypeError: unhashable type. Why did this happen, and how do you correctly implement equality and hashing? Mid-levelTell me how mutable data types in Python differ from immutable ones. Give examples and explain why it matters in practice. Junior

Answer by voice

The interviewer will ask this question and listen. Think out loud and ask for a hint if you need one. When you're done, pause or tap “That's my answer”. In about a minute, your score and the points you covered show up here.

Sign in to answer

Best with headphones · ~4 min