Python OOPs Interview Questions PDF

Object-Oriented Programming (OOP) is something you really need to know if you want to work with Python. It helps you write code that’s easier to manage and use again in different projects. Python OOPs is very useful when you’re working on real Python projects like building websites, analyzing data.

This is why companies ask about OOPs Questions in interviews. They want to see if you understand how to organize your code properly and build systems that can grow without breaking. It’s not just about knowing the theory, they want to know you can actually use these concepts to solve real problems.

We put together this list of Python OOPs interview questions for people who are just starting out and those who have been coding for a while. You’ll find questions that test how you’d handle actual situations you might face at work.

Python OOPs Interview Questions and Answers for Freshers

Que 1. What are the main principles of OOP in Python?

Python supports four key OOP principles:

  • Encapsulation: Bundling data and methods in a single unit.
  • Abstraction: Hiding internal details and showing only essential features.
  • Inheritance: One class can derive attributes and methods from another.
  • Polymorphism: The ability to present the same interface for different data types.

These principles allow for code reuse and scalability.

Que 2. How is encapsulation implemented in Python?

Encapsulation is implemented using private and protected access modifiers:

class Employee:
    def __init__(self, name):
        self._name = name       # protected
        self.__salary = 50000   # private

    def get_salary(self):
        return self.__salary

Private variables use double underscores __, and protected variables use a single underscore _.

Que 3. What is the difference between a class and an object in Python?

  • Class: Blueprint for creating objects. It defines attributes and behavior.
  • Object: An instance of a class.

Example:

class Car:
    def start(self):
        print("Engine started")

my_car = Car()
my_car.start()

Que 4. How does inheritance work in Python?

Inheritance allows a class (child) to acquire methods and properties of another class (parent).

class Animal:
    def speak(self):
        print("Animal speaks")

class Dog(Animal):
    def bark(self):
        print("Dog barks")

d = Dog()
d.speak()

Que 5. What are dunder methods in Python OOP?

Dunder methods (like __init__, __str__, __len__) are special methods with double underscores. They let you define object behavior for built-in functions.

Example:

class Book:
    def __init__(self, title):
        self.title = title

    def __str__(self):
        return f"Book title: {self.title}"

Que 6. How is polymorphism implemented in Python?

Polymorphism allows different classes to have methods with the same name, enabling flexible code:

class Dog:
    def speak(self):
        return "Woof"

class Cat:
    def speak(self):
        return "Meow"

def animal_sound(animal):
    print(animal.speak())

Que 7. What is method overloading in Python?

Python doesn’t support traditional method overloading. Instead, use default arguments or variable arguments:

class Calculator:
    def add(self, a, b=0, c=0):
        return a + b + c

Que 8. Explain the use of super() in Python.

super() is used to call methods from a parent class, especially in method overriding.

class A:
    def show(self):
        print("Class A")

class B(A):
    def show(self):
        super().show()
        print("Class B")

Que 9. What is a constructor in Python?

The __init__() method is a constructor in Python. It initializes the object.

class Student:
    def __init__(self, name):
        self.name = name

Que 10. What is object composition?

Object composition means building complex objects using simpler objects as attributes.

class Engine:
    def start(self):
        print("Engine running")

class Car:
    def __init__(self):
        self.engine = Engine()

    def drive(self):
        self.engine.start()

Que 11. How is abstraction implemented in Python?

Python uses abstract base classes with the abc module:

from abc import ABC, abstractmethod

class Animal(ABC):
    @abstractmethod
    def sound(self):
        pass

Que 12. What is the difference between is and == in Python?

  • == checks value equality.
  • is checks identity (same memory location).

Que 13. What is the use of the str() method?

__str__() defines how an object is represented as a string:

class User:
    def __str__(self):
        return "User object"

Que 14. How can you protect a class variable?

Use a single underscore _var for protected and double underscore __var for private variables.

Que 15. Can a class inherit from multiple classes in Python?

Yes, Python supports multiple inheritance:

class A:
    pass

class B:
    pass

class C(A, B):
    pass

Que 16. What is the difference between class method and static method?

FeatureClass MethodStatic Method
Decorator@classmethod@staticmethod
First ArgumentclsNone
Access Class DataYesNo
UsageFor factory methodsUtility functions

Que 17. What is the role of del() in Python?

__del__() is the destructor method, called when an object is deleted. Not commonly used due to Python’s garbage collection.

Que 18. What is duck typing in Python?

Duck typing focuses on behavior rather than inheritance. “If it walks like a duck and quacks like a duck…”

Example:

class Duck:
    def quack(self):
        print("Quack!")

def make_it_quack(thing):
    thing.quack()

Que 19. What are properties in Python classes?

Properties provide controlled access to class attributes using @property.

class Account:
    def __init__(self, balance):
        self._balance = balance

    @property
    def balance(self):
        return self._balance

Que 20. How do you create a read-only attribute in Python?

Use @property without a setter:

class Config:
    def __init__(self):
        self._version = "1.0"

    @property
    def version(self):
        return self._version
Python OOPs Interview Questions

Also Check: Python Interview Questions and Answers PDF

Python OOPs Interview Questions and Answers for Experienced

Que 21. What are metaclasses in Python and how are they used?

A metaclass in Python is a class of a class that defines how a class behaves. A class is an instance of a metaclass.

class Meta(type):
    def __new__(cls, name, bases, dct):
        print("Creating class", name)
        return super().__new__(cls, name, bases, dct)

class MyClass(metaclass=Meta):
    pass

They’re useful for class validation and automatic method injection.

Que 22. Explain the difference between @classmethod, @staticmethod, and instance methods in real-world usage.

  • Instance Methods operate on instance data.
  • Class Methods access class-level data and are often used as factory methods.
  • Static Methods are utility functions, do not access instance or class data.

Que 23. How does Python support multiple inheritance and how does MRO resolve conflicts?

Python uses the C3 linearization algorithm for Method Resolution Order (MRO). You can view the MRO using Class.__mro__.

class A: pass
class B(A): pass
class C(A): pass
class D(B, C): pass

print(D.__mro__)

It determines which class method is called during inheritance conflicts.

Que 24. What are descriptors and how are they different from properties?

Descriptors are objects that define __get__, __set__, and __delete__. Properties are implemented using descriptors.

class Descriptor:
    def __get__(self, obj, type=None):
        return "value"

Descriptors provide reusable attribute access control.

Que 25. What is monkey patching in Python?

Monkey patching refers to modifying classes or modules at runtime.

import datetime

def fake_now():
    return "2025-01-01"

datetime.datetime.now = fake_now

It’s useful in testing but risky for production.

Que 26. What is the role of slots in a Python class?

__slots__ is used to restrict dynamic creation of attributes and save memory.

class Point:
    __slots__ = ['x', 'y']

This avoids the per-instance __dict__ and makes objects lightweight.

Que 27. How would you implement an interface in Python?

Python doesn’t have explicit interfaces. Instead, it uses Abstract Base Classes (ABC).

from abc import ABC, abstractmethod

class Shape(ABC):
    @abstractmethod
    def area(self):
        pass

Any subclass must implement the abstract methods.

Que 28. How would you implement custom iterators in Python classes?

By defining __iter__() and __next__() methods:

class Counter:
    def __init__(self):
        self.num = 0

    def __iter__(self):
        return self

    def __next__(self):
        if self.num >= 5:
            raise StopIteration
        self.num += 1
        return self.num

Que 29. What’s the difference between deep copy and shallow copy in object references?

AspectShallow CopyDeep Copy
CopiesReferences of nested objectsEntire object recursively
Modulecopy.copy()copy.deepcopy()
Use CaseLess memory, shared dataIsolated duplicate objects

Que 30. How can you enforce singleton design pattern in Python?

class Singleton:
    _instance = None
    def __new__(cls):
        if cls._instance is None:
            cls._instance = super(Singleton, cls).__new__(cls)
        return cls._instance

Singleton ensures only one instance of a class is created.

Que 31. How does Python handle access modifiers differently than Java/C++?

Python uses naming conventions instead of keywords:

  • _var: Protected (by convention)
  • __var: Private (name mangled)
  • No real enforcement like in Java/C++

Que 32. How would you override equality (==) and hashing in custom Python classes?

Override __eq__ and __hash__:

class User:
    def __init__(self, id):
        self.id = id

    def __eq__(self, other):
        return self.id == other.id

    def __hash__(self):
        return hash(self.id)

Useful for using objects in sets or as dict keys.

Que 33. What’s the role of call() in Python classes?

Allows an object to behave like a function:

class Multiplier:
    def __call__(self, x):
        return x * 2

m = Multiplier()
m(5)  # Returns 10

Que. 34 How would you model private static constants in Python OOP?

Use class-level variables with leading underscores:

class Config:
    _API_KEY = "secret123"

Python doesn’t have true constants, but naming indicates intent.

Que. 35 Explain covariance and contravariance with respect to method overriding.

Covariance allows a method to return a subtype of the parent method’s return type. Contravariance allows parameters to be supertypes.

Python supports these through duck typing rather than enforced types.

Que 36. How does inheritance interact with Python dataclasses?

When using @dataclass, inheritance includes fields from the base class:

from dataclasses import dataclass

@dataclass
class Animal:
    age: int

@dataclass
class Dog(Animal):
    breed: str

It simplifies boilerplate for OOP models.

Que 37. Can you implement polymorphism without inheritance in Python?

Yes. Using duck typing, different classes implement the same method names:

class PDF:
    def render(self): print("PDF")

class Image:
    def render(self): print("Image")

def render_content(doc): doc.render()

Que 38. What is the observer pattern and how would you implement it in Python?

Observer pattern allows objects (observers) to get notified on changes in another (subject):

class Subject:
    def __init__(self):
        self.observers = []

    def register(self, observer):
        self.observers.append(observer)

    def notify(self, msg):
        for obs in self.observers:
            obs.update(msg)

Que 39. What are weak references and why are they useful in Python?

Weak references allow one object to refer to another without increasing its reference count. Useful in caching:

import weakref
class Data: pass

obj = Data()
ref = weakref.ref(obj)

Que 40. How would you unit test OOP classes in Python?

Use unittest or pytest:

  • Test each method of the class in isolation.
  • Use mocks for dependencies.
  • Ensure constructor, methods, and inheritance behaviors are tested.
import unittest

class TestMyClass(unittest.TestCase):
    def test_add(self):
        obj = MyClass()
        self.assertEqual(obj.add(2, 3), 5)

Also Check: C# OOPs Interview Questions

Python Scenario Based OOPs Interview Questions and Answers

Que 41. How would you design a class hierarchy for different types of accounts in a banking system?

You can use inheritance to define common behavior in a base class and then specialize:

class Account:
    def __init__(self, balance):
        self.balance = balance

    def deposit(self, amount):
        self.balance += amount

    def get_balance(self):
        return self.balance

class SavingsAccount(Account):
    def __init__(self, balance, interest_rate):
        super().__init__(balance)
        self.interest_rate = interest_rate

class CurrentAccount(Account):
    def __init__(self, balance, overdraft_limit):
        super().__init__(balance)
        self.overdraft_limit = overdraft_limit

Use inheritance when objects share structure and behavior.

Que 42. Suppose you’re building an ecommerce system. How would you represent products with common and category-specific attributes?

Use inheritance and composition:

class Product:
    def __init__(self, name, price):
        self.name = name
        self.price = price

class Electronics(Product):
    def __init__(self, name, price, warranty_years):
        super().__init__(name, price)
        self.warranty_years = warranty_years

class Book(Product):
    def __init__(self, name, price, author):
        super().__init__(name, price)
        self.author = author

This makes code cleaner and scalable.

Que 43. How would you implement a plugin system using OOP concepts in Python?

Use polymorphism and abstract base classes to define interfaces:

from abc import ABC, abstractmethod

class Plugin(ABC):
    @abstractmethod
    def execute(self):
        pass

class ImageProcessor(Plugin):
    def execute(self):
        print("Processing image...")

class VideoProcessor(Plugin):
    def execute(self):
        print("Processing video...")

def run_plugin(plugin: Plugin):
    plugin.execute()

Que 44. You have to implement logging for multiple classes without modifying their core logic. How would you apply OOP here?

Use composition or decorators for separation of concerns:

class Logger:
    def log(self, message):
        print("Log:", message)

class Service:
    def __init__(self, logger):
        self.logger = logger

    def run(self):
        self.logger.log("Service started")

Logger is injected into the class, allowing decoupling.

Que 45. How would you enforce that certain methods must be implemented by subclasses?

Use abc module to define abstract base classes:

from abc import ABC, abstractmethod

class Report(ABC):
    @abstractmethod
    def generate(self):
        pass

class SalesReport(Report):
    def generate(self):
        print("Generating sales report")

If a subclass doesn’t implement the abstract method, Python raises an error.

Que 46. Imagine you need to track the number of active objects for a class. How would you implement that?

Use a class variable to track instance count:

class Connection:
    active_connections = 0

    def __init__(self):
        Connection.active_connections += 1

    def __del__(self):
        Connection.active_connections -= 1

This allows you to monitor instance lifecycles globally.

Que 47. How can you prevent the creation of more than one object of a class (singleton)?

class Singleton:
    _instance = None

    def __new__(cls):
        if cls._instance is None:
            cls._instance = super(Singleton, cls).__new__(cls)
        return cls._instance

Used for configurations, logging, etc.

Que 48. You’re creating a class for geometric shapes. How would you ensure that each shape must implement its own area() method?

Use abstract methods:

from abc import ABC, abstractmethod

class Shape(ABC):
    @abstractmethod
    def area(self):
        pass

class Circle(Shape):
    def __init__(self, radius):
        self.radius = radius

    def area(self):
        return 3.14 * self.radius * self.radius

Each subclass is now required to provide its own logic for area.

Que 49. How can you model a real-world problem like a library system with OOP?

Use multiple classes and relationships:

  • Book (title, author, ISBN)
  • Member (name, ID, borrowed_books)
  • Library (list of books, list of members)

Use composition and object references:

class Book:
    def __init__(self, title):
        self.title = title

class Member:
    def __init__(self, name):
        self.name = name
        self.borrowed_books = []

    def borrow(self, book):
        self.borrowed_books.append(book)

Que 50. You’re building a data pipeline. How would you use OOP to ensure reusable and testable code?

Model each pipeline step as a class with a common interface:

class Step(ABC):
    @abstractmethod
    def process(self, data):
        pass

class CleanStep(Step):
    def process(self, data):
        return [d.strip() for d in data]

class TransformStep(Step):
    def process(self, data):
        return [d.upper() for d in data]

Then chain these steps in a pipeline controller.

Que 51. How would you design a system where different file types (e.g., PDF, DOCX, CSV) need to be read using a common interface?

You can use polymorphism with a base abstract class and override the read() method for each specific file type.

from abc import ABC, abstractmethod

class FileReader(ABC):
    @abstractmethod
    def read(self, file_path):
        pass

class PDFReader(FileReader):
    def read(self, file_path):
        print(f"Reading PDF content from {file_path}")

class CSVReader(FileReader):
    def read(self, file_path):
        print(f"Reading CSV content from {file_path}")

class DOCXReader(FileReader):
    def read(self, file_path):
        print(f"Reading DOCX content from {file_path}")

def process_file(reader: FileReader, path: str):
    reader.read(path)

# Example usage
pdf = PDFReader()
process_file(pdf, "sample.pdf")
Python OOPs Interview Questions Answers

Also Check: Java OOPs Interview Questions

Python OOPs Interview Questions PDF

We have added all these Python OOPs Interview Questions and Answers into a PDF.

You can download it and use it as your go-to reference while preparing for your Python interviews