OOP Python Textbook
OOP Python Textbook
Introduction: Preface
Preface
using Python.
It begins with foundational programming paradigms and gradually advances to complex OOP concepts such
as polymorphism,
abstraction, and class relationships like aggregation and composition. Each chapter includes theoretical
concepts,
real-world examples, practical activities, and applications to ensure a deep understanding of the subject.
This book is suitable for students, professionals, and anyone who wants to master OOP in Python.
Happy Learning!
Topics:
- Comparison with procedural programming: OOP focuses on objects and data, procedural focuses on
functions.
Lab Activity:
Example:
class Person:
self.name = name
def greet(self):
p = Person("Alice")
p.greet()
Applications:
- Used in software systems requiring modularity and reusability like games, GUI apps, etc.
Topics:
Assignment:
Example:
class BankAccount:
self.owner = owner
Object-Oriented Programming with Python - Course Outline
self.__balance = balance
self.__balance += amount
def get_balance(self):
return self.__balance
acc.deposit(500)
print(acc.get_balance())
Applications:
Topics:
Lab Activity:
Example:
class Employee:
Object-Oriented Programming with Python - Course Outline
self.__name = name
self.__salary = salary
@property
def salary(self):
return self.__salary
@salary.setter
if amount > 0:
self.__salary = amount
emp.salary = 6000
print(emp.salary)
Applications:
Week 4: Inheritance
Topics:
Assignment:
Example:
class Animal:
def speak(self):
print("Animal speaks")
class Dog(Animal):
def speak(self):
super().speak()
print("Dog barks")
d = Dog()
d.speak()
Applications:
Topics:
Lab Activity:
Example:
Object-Oriented Programming with Python - Course Outline
class Math:
return a + b + c
m = Math()
print(m.add(2))
print(m.add(2, 3))
print(m.add(2, 3, 4))
Applications:
Topics:
Quiz:
Example:
class Shape:
def area(self):
print("Calculating area")
class Circle(Shape):
def area(self):
Object-Oriented Programming with Python - Course Outline
print("Area of Circle")
s = Shape()
c = Circle()
s.area()
c.area()
Applications:
Topics:
Assignment:
Example:
class Vehicle(ABC):
@abstractmethod
def start(self):
pass
Object-Oriented Programming with Python - Course Outline
class Car(Vehicle):
def start(self):
print("Car started")
v = Car()
v.start()
Applications:
Topics:
Lab Activity:
Example:
class Engine:
self.power = power
class Car:
self.engine = engine
e = Engine("200 HP")
c = Car(e)
print(c.engine.power)
Applications: