
Python Object-Oriented Programming
Classes, objects, inheritance, encapsulation, polymorphism, special methods, decorators
1What is a class in Python?
What is a class in Python?
Answer
A class is a blueprint for creating objects that share the same attributes and methods. It defines the structure and behavior of objects that will be instantiated from it. Classes allow organizing code in a modular and reusable way by grouping related data and functionality together.
2What is the role of the __init__ method in a Python class?
What is the role of the __init__ method in a Python class?
Answer
The __init__ method is the class constructor. It is automatically called when creating a new instance and allows initializing object attributes with specific values. This is where you typically define the initial state of the object by assigning values to instance attributes via self.
3What does the self parameter represent in class methods?
What does the self parameter represent in class methods?
Answer
The self parameter represents the current instance of the class. It allows accessing object attributes and methods from within the class. While the name self is a convention, it is strongly recommended to use it for code readability. Python automatically passes the instance as the first argument when calling a method.
What is the difference between a class attribute and an instance attribute?
How to create an instance of a class named Person in Python?
+17 interview questions
Other Data Science & ML interview topics
Python Basics
Python Data Structures
Git Fundamentals
SQL Basics
NumPy Fundamentals
Pandas Basics
Jupyter & Google Colab
SQL Joins & Advanced Queries
Advanced Pandas
Visualization with Matplotlib & Seaborn
Interactive Visualizations with Plotly
Descriptive Statistics
Inferential Statistics
Web Scraping
BigQuery & Cloud Data
Feature Engineering
Supervised ML: Regression
Supervised ML: Classification
Decision Trees & Ensembles
Unsupervised ML
ML Pipelines & Validation
Time Series & Forecasting
Deep Learning Fundamentals
TensorFlow & Keras
CNN & Image Classification
RNN & Sequences
Transformers & Attention
NLP & Hugging Face
GenAI & LangChain
MLOps & Deployment
Master Data Science & ML for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free