Python · Module 6Module material
Objects and Classes interview questions
25 questions interviewers ask on this module’s topics, from first principles to the follow-ups. Each comes with a model answer.
Classes and objects
- What is the difference between a class and an instance?●
- What is
self?● - What does
__init__do? Is it the constructor?● - What happens if a method has no
selfparameter?●● - Where are an object's attributes stored?●●
- Why is setting a misspelt attribute dangerous?●●
- What is the difference between
==andisfor your own objects?●● - What are special methods (dunder methods)? Give examples.●●
- What is the difference between
__repr__and the default display?●● - "Everything in Python is an object." What does that mean in practice?●
Inheritance
- What is inheritance?●
- What does
super().__init__(...)do, and what happens without it?●● - How do you define a custom exception, and why subclass a built-in one?●●
Dataclasses
- What does
@dataclassgenerate?● - Does a dataclass check its type hints?●●
- Why can a dataclass field not have
[]as its default?●● - What does
frozen=Truedo, and when would you use it?●● - What is a decorator?●●
The estimator pattern
- What is the estimator pattern?●
- Why do learned attributes end in an underscore?●●
- Why does
fitreturnself?●● - What is the difference between a parameter and a hyperparameter?●●
- How does k-nearest neighbours regression predict?●●
- Why should
fitstore a copy of the data it is given?●● - Why is a model's error on its own training data a poor measure?●●