SlideShare a Scribd company logo
Object-Oriented Programming in Python
Classes, Objects, Inheritance, Polymorphism More
Madhusudhana Rao Baswani
Python Training Series
July 23, 2025
Agenda
1 OOP Basics
2 Core Terminology
3 Classes & Objects
4 Constructors & Methods
5 Encapsulation
6 Inheritance
7 Polymorphism
8 Abstraction
Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 2 / 17
What is OOP?
Programming style that bundles data & operations
into objects.
Promotes modular, reusable, and maintainable code.
Key pillars: Encapsulation, Inheritance, Polymorphism, and Abstraction.
Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 3 / 17
Why OOP in Python?
Everything in Python is an object — even functions and types.
Easy syntax for defining classes and methods.
Supports dynamic typing and duck typing for flexible design.
Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 4 / 17
Glossary
Class Blueprint for creating objects.
Object Instance of a class containing state & behavior.
Data Member Variable defined in a class (instance or static).
Method Function defined inside a class.
Instance/Static & Local Vars Object-level, class-level, and method-scope variables.
Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 5 / 17
Defining a Class
class Student:
""" Represents a student entity """
school = "Leela High" # static var
def __init__(self , name , marks):
self.name = name # instance vars
self.marks = marks
Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 6 / 17
Instantiating Objects
s1 = Student("Kajal", 90)
s2 = Student("Rohith", 85)
print(s1.name , s1.marks)
Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 7 / 17
Constructor
i nit
Automatically invoked during object creation.
First parameter self points to the current object.
Used to initialize instance variables.
Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 8 / 17
Method Types
Type First Param
Instance Method self (object)
Class Method cls (class)
Static Method none
Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 9 / 17
Example: Class & Static Methods
class MathDemo:
factor = 2 # static variable
@classmethod
def double(cls , x):
return x * cls.factor # uses class var
@staticmethod
def add(x, y):
return x + y
Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 10 / 17
Private Attributes
class Car:
def __init__(self):
self.__maxspeed = 200 # private
def drive(self):
print(self.__maxspeed)
Access via name-mangling: obj._Car__maxspeed
Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 11 / 17
Single Inheritance
class Animal:
def eat(self):
print(’Eating ’)
class Dog(Animal):
def bark(self):
print(’Barking ’)
d = Dog(); d.eat(); d.bark()
Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 12 / 17
Types of Inheritance
Single
Multiple
Multilevel
Hierarchical
Hybrid
Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 13 / 17
Compile-time vs Runtime
Operator Overloading: + works for numbers and strings.
Method Overloading: Not natively supported; emulate with default/args.
Method Overriding: Redefine a parent method in child class.
Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 14 / 17
Operator Overloading Example
class Book:
def __init__(self , pages):
self.pages = pages
def __add__(self , other):
return self.pages + other.pages
print(Book (100) + Book (200)) # 300
Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 15 / 17
Abstract Base Class
from abc import ABC , abstractmethod
class Shape(ABC):
@abstractmethod
def area(self):
pass
Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 16 / 17
Questions?
Thank You!
Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 17 / 17

More Related Content

PPTX
Object-Oriented Programming in Python.pptx
ssuser4ab3a2
 
PPSX
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 
PDF
python note.pdf
Nagendra504676
 
PPTX
software construction and development week 3 Python lists, tuples, dictionari...
MuhammadBilalAjmal2
 
PPTX
Introduction to OOP_Python_Lecture1.pptx
cpics
 
PPTX
OOPS 46 slide Python concepts .pptx
mrsam3062
 
PPTX
UNIT 3 PY.pptx - OOPS CONCEPTS IN PYTHON
drkangurajuphd
 
PPTX
Object Oriented Programming.pptx
SAICHARANREDDYN
 
Object-Oriented Programming in Python.pptx
ssuser4ab3a2
 
OOPS Concepts in Python and Exception Handling
Dr. A. B. Shinde
 
python note.pdf
Nagendra504676
 
software construction and development week 3 Python lists, tuples, dictionari...
MuhammadBilalAjmal2
 
Introduction to OOP_Python_Lecture1.pptx
cpics
 
OOPS 46 slide Python concepts .pptx
mrsam3062
 
UNIT 3 PY.pptx - OOPS CONCEPTS IN PYTHON
drkangurajuphd
 
Object Oriented Programming.pptx
SAICHARANREDDYN
 

Similar to Object Oriented Programming by Using Python (20)

PPTX
Python programming computer science and engineering
IRAH34
 
PDF
Unit 3-Classes ,Objects and Inheritance.pdf
Harsha Patil
 
PPTX
Class and Objects in python programming.pptx
Rajtherock
 
PPTX
OOP concepts -in-Python programming language
SmritiSharma901052
 
PDF
Object oriented Programning Lanuagues in text format.
SravaniSravani53
 
PPTX
object-class_in python programming .pptx
SnehasisGhosh10
 
PPTX
Slide - FPT University - PFP191 - Chapter 11 - Objects
cMai28
 
PPTX
Problem solving with python programming OOP's Concept
rohitsharma24121
 
PPTX
Python Lecture 13
Inzamam Baig
 
PPTX
Python-Classes.pptx
Karudaiyar Ganapathy
 
PPTX
Class_and_Object_with_Example_Python.pptx janbsbznnsbxghzbbshvxnxhnwn
bandiranvitha
 
PPTX
object oriented programming(PYTHON)
Jyoti shukla
 
PPTX
PYTHON OBJECT-ORIENTED PROGRAMMING.pptx
hpearl130
 
PPTX
python programming language unit 5 ppt.pptx
ZeusOp1
 
PPTX
Regex,functions, inheritance,class, attribute,overloding
sangumanikesh
 
PPTX
PYTHON - OBJECT ORIENTED PROGRAMMING .pptx
SubashiniRathinavel
 
PPTX
Python aplicado a Inteligencia artificial y machine learning. Dia 91.
chekov2500
 
PPTX
Object oriented Programming concepts explained(3).pptx
grad25iconinfocus
 
PPTX
Python advance
Mukul Kirti Verma
 
Python programming computer science and engineering
IRAH34
 
Unit 3-Classes ,Objects and Inheritance.pdf
Harsha Patil
 
Class and Objects in python programming.pptx
Rajtherock
 
OOP concepts -in-Python programming language
SmritiSharma901052
 
Object oriented Programning Lanuagues in text format.
SravaniSravani53
 
object-class_in python programming .pptx
SnehasisGhosh10
 
Slide - FPT University - PFP191 - Chapter 11 - Objects
cMai28
 
Problem solving with python programming OOP's Concept
rohitsharma24121
 
Python Lecture 13
Inzamam Baig
 
Python-Classes.pptx
Karudaiyar Ganapathy
 
Class_and_Object_with_Example_Python.pptx janbsbznnsbxghzbbshvxnxhnwn
bandiranvitha
 
object oriented programming(PYTHON)
Jyoti shukla
 
PYTHON OBJECT-ORIENTED PROGRAMMING.pptx
hpearl130
 
python programming language unit 5 ppt.pptx
ZeusOp1
 
Regex,functions, inheritance,class, attribute,overloding
sangumanikesh
 
PYTHON - OBJECT ORIENTED PROGRAMMING .pptx
SubashiniRathinavel
 
Python aplicado a Inteligencia artificial y machine learning. Dia 91.
chekov2500
 
Object oriented Programming concepts explained(3).pptx
grad25iconinfocus
 
Python advance
Mukul Kirti Verma
 
Ad

Recently uploaded (20)

PPTX
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
PDF
5.EXPLORING-FORCES-Detailed-Notes.pdf/8TH CLASS SCIENCE CURIOSITY
Sandeep Swamy
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PPTX
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
PDF
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
PDF
Landforms and landscapes data surprise preview
jpinnuck
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PDF
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
PPTX
Congenital Hypothyroidism pptx
AneetaSharma15
 
PDF
7.Particulate-Nature-of-Matter.ppt/8th class science curiosity/by k sandeep s...
Sandeep Swamy
 
PPT
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
Measures_of_location_-_Averages_and__percentiles_by_DR SURYA K.pptx
Surya Ganesh
 
5.EXPLORING-FORCES-Detailed-Notes.pdf/8TH CLASS SCIENCE CURIOSITY
Sandeep Swamy
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PPTs-The Rise of Empiresghhhhhhhh (1).pptx
academysrusti114
 
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
Arihant Class 10 All in One Maths full pdf
sajal kumar
 
Landforms and landscapes data surprise preview
jpinnuck
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
Congenital Hypothyroidism pptx
AneetaSharma15
 
7.Particulate-Nature-of-Matter.ppt/8th class science curiosity/by k sandeep s...
Sandeep Swamy
 
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
Ad

Object Oriented Programming by Using Python

  • 1. Object-Oriented Programming in Python Classes, Objects, Inheritance, Polymorphism More Madhusudhana Rao Baswani Python Training Series July 23, 2025
  • 2. Agenda 1 OOP Basics 2 Core Terminology 3 Classes & Objects 4 Constructors & Methods 5 Encapsulation 6 Inheritance 7 Polymorphism 8 Abstraction Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 2 / 17
  • 3. What is OOP? Programming style that bundles data & operations into objects. Promotes modular, reusable, and maintainable code. Key pillars: Encapsulation, Inheritance, Polymorphism, and Abstraction. Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 3 / 17
  • 4. Why OOP in Python? Everything in Python is an object — even functions and types. Easy syntax for defining classes and methods. Supports dynamic typing and duck typing for flexible design. Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 4 / 17
  • 5. Glossary Class Blueprint for creating objects. Object Instance of a class containing state & behavior. Data Member Variable defined in a class (instance or static). Method Function defined inside a class. Instance/Static & Local Vars Object-level, class-level, and method-scope variables. Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 5 / 17
  • 6. Defining a Class class Student: """ Represents a student entity """ school = "Leela High" # static var def __init__(self , name , marks): self.name = name # instance vars self.marks = marks Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 6 / 17
  • 7. Instantiating Objects s1 = Student("Kajal", 90) s2 = Student("Rohith", 85) print(s1.name , s1.marks) Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 7 / 17
  • 8. Constructor i nit Automatically invoked during object creation. First parameter self points to the current object. Used to initialize instance variables. Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 8 / 17
  • 9. Method Types Type First Param Instance Method self (object) Class Method cls (class) Static Method none Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 9 / 17
  • 10. Example: Class & Static Methods class MathDemo: factor = 2 # static variable @classmethod def double(cls , x): return x * cls.factor # uses class var @staticmethod def add(x, y): return x + y Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 10 / 17
  • 11. Private Attributes class Car: def __init__(self): self.__maxspeed = 200 # private def drive(self): print(self.__maxspeed) Access via name-mangling: obj._Car__maxspeed Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 11 / 17
  • 12. Single Inheritance class Animal: def eat(self): print(’Eating ’) class Dog(Animal): def bark(self): print(’Barking ’) d = Dog(); d.eat(); d.bark() Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 12 / 17
  • 13. Types of Inheritance Single Multiple Multilevel Hierarchical Hybrid Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 13 / 17
  • 14. Compile-time vs Runtime Operator Overloading: + works for numbers and strings. Method Overloading: Not natively supported; emulate with default/args. Method Overriding: Redefine a parent method in child class. Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 14 / 17
  • 15. Operator Overloading Example class Book: def __init__(self , pages): self.pages = pages def __add__(self , other): return self.pages + other.pages print(Book (100) + Book (200)) # 300 Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 15 / 17
  • 16. Abstract Base Class from abc import ABC , abstractmethod class Shape(ABC): @abstractmethod def area(self): pass Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 16 / 17
  • 17. Questions? Thank You! Madhusudhana Rao Baswani (Python Training Series) Object-Oriented Programming in Python July 23, 2025 17 / 17