Object-Oriented Programming in
Python – A Lecture Note
Prepared as an academic resource
Table of Contents
Introduction
Object-Oriented Programming (OOP) is a programming paradigm that uses objects and
classes. Python supports OOP through classes, inheritance, encapsulation, and
polymorphism.
Learning Objectives
- Understand the principles of OOP
- Implement classes and objects in Python
- Use inheritance and method overriding
Theoretical Background
OOP helps in structuring a program into simple, reusable pieces of code. Key concepts
include:
- Class & Object
- Inheritance
- Encapsulation
- Polymorphism
Example Code
class Animal:
def __init__(self, name):
self.name = name
def speak(self):
return f"{self.name} makes a sound."
class Dog(Animal):
def speak(self):
return f"{self.name} barks."
d = Dog("Buddy")
print(d.speak())
Summary
OOP allows for cleaner code architecture and reuse. Python’s dynamic typing makes OOP
flexible.
Review Questions
- What is inheritance?
- How does polymorphism work in Python?
- Explain encapsulation with an example.