Object Oriented
Programming Using
Python
1
1. Introduction to Object Oriented Programming in Python
2. Difference between object and procedural oriented
programming
3. What are Classes and Objects?
4. Object-Oriented Programming methodologies:
• Inheritance
• Polymorphism
• Encapsulation
• Abstraction
2
Index
3
1. Introduction to Object Oriented
Programming in Python
Object Oriented Programming is a way of
computer programming using the idea of
“objects” to represents data and methods. It is
also, an approach used for creating neat and
reusable code instead of a redundant one.
2. Difference between Object-Oriented and
Procedural Oriented Programming
Object-Oriented Programming (OOP)
Procedural-Oriented Programming
(Pop)
It is a bottom-up approach It is a top-down approach
Program is divided into objects Program is divided into functions
Makes use of Access modifiers
‘public’, private’, protected’
Doesn’t use Access modifiers
It is more secure It is less secure
Object can move freely within member
functions
Data can move freely from function to
function within programs
It supports inheritance It does not support inheritance
5
class class1(): // class 1 is the name of the class
A class is a collection of objects or you can say it is a
blueprint of objects defining the common attributes and
behavior. Now the question arises, how do you do that?
Class is defined under a “Class” Keyword.
Example:
3. What are Classes and Objects?
6
class employee():
def __init__(self,name,age,id,salary): //creating a function
self.name = name // self is an instance of a class
self.age = age
self.salary = salary
self.id = id
emp1 = employee("harshit",22,1000,1234) //creating objects
emp2 = employee("arjun",23,2000,2234)
print(emp1.__dict__)//Prints dictionary
Creating an Object and Class in python:
Example:
7
❑ Inheritance
❑ Polymorphism
❑ Encapsulation
❑ Abstraction
4. Object-Oriented Programming
methodologies:
Inheritance:
Ever heard of this dialogue from relatives “you look exactly
like your father/mother” the reason behind this is called
‘inheritance’. From the Programming aspect, It generally
means “inheriting or transfer of characteristics from parent to
child class without any modification”. The new class is called
the derived/child class and the one from which it is derived is
called a parent/base class.
9
Single Inheritance:
Single level inheritance enables a derived class to inherit
characteristics from a single parent class.
class employee1()://This is a parent class
def __init__(self, name, age, salary):
self.name = name
self.age = age
self.salary = salary
class childemployee(employee1)://This is a child class
def __init__(self, name, age, salary,id):
self.name = name
self.age = age
self.salary = salary
self.id = id
emp1 = employee1('harshit',22,1000)
print(emp1.age)
Example:
Output: 22
Multilevel Inheritance:
Multi-level inheritance enables a derived class to inherit properties from an
immediate parent class which in turn inherits properties from his parent
class.
class employee()://Super class
def __init__(self,name,age,salary):
self.name = name
self.age = age
self.salary = salary
class childemployee1(employee)://First child class
def __init__(self,name,age,salary):
self.name = name
self.age = age
self.salary = salary
Example:
class childemployee2(childemployee1)://Second child class
def __init__(self, name, age, salary):
self.name = name
self.age = age
self.salary = salary
emp1 = employee('harshit',22,1000)
emp2 = childemployee1('arjun',23,2000)
print(emp1.age)
print(emp2.age)
Output: 22,23
Hierarchical Inheritance:
Hierarchical level inheritance enables more than one derived
class to inherit properties from a parent class.
class employee():
def __init__(self, name, age, salary): //Hierarchical Inheritance
self.name = name
self.age = age
self.salary = salary
Example:
class childemployee1(employee):
def __init__(self,name,age,salary):
self.name = name
self.age = age
self.salary = salary
class childemployee2(employee):
def __init__(self, name, age, salary):
self.name = name
self.age = age
self.salary = salary
emp1 = employee('harshit',22,1000)
emp2 = employee('arjun',23,2000)
Multiple Inheritance:
Multiple level inheritance enables one derived class to inherit
properties from more than one base class.
class employee1(): //Parent class
def __init__(self, name, age, salary):
self.name = name
self.age = age
self.salary = salary
Example:
class employee2(): //Parent class
def __init__(self,name,age,salary,id):
self.name = name
self.age = age
self.salary = salary
self.id = id
class childemployee(employee1,employee2):
def __init__(self, name, age, salary,id):
self.name = name
self.age = age
self.salary = salary
self.id = id
emp1 = employee1('harshit',22,1000)
emp2 = employee2('arjun',23,2000,1234)
Polymorphism:
You all must have used GPS for navigating the route, Isn’t it
amazing how many different routes you come across for the
same destination depending on the traffic, from a
programming point of view this is called ‘polymorphism’. It is
one such OOP methodology where one task can be performed
in several different ways. To put it in simple words, it is a
property of an object which allows it to take multiple forms.
19
20
Polymorphism is of two types:
❑ Compile-time Polymorphism
❑ Run-time Polymorphism
21
Compile-time Polymorphism:
A compile-time polymorphism also called as static
polymorphism which gets resolved during the compilation
time of the program. One common example is “method
overloading”
22
class employee1():
def name(self):
print("Harshit is his name")
def salary(self):
print("3000 is his salary")
def age(self):
print("22 is his age")
class employee2():
def name(self):
print("Rahul is his name")
def salary(self):
print("4000 is his salary")
def age(self):
print("23 is his age")
Example:
23
def func(obj)://Method Overloading
obj.name()
obj.salary()
obj.age()
obj_emp1 = employee1()
obj_emp2 = employee2()
func(obj_emp1)
func(obj_emp2)
Output:
Harshit is his name
3000 is his salary
22 is his age
Rahul is his name
4000 is his salary
23 is his age
24
Run-time Polymorphism:
A run-time Polymorphism is also, called as dynamic
polymorphism where it gets resolved into the run time. One
common example of Run-time polymorphism is “method
overriding”.
25
class employee():
def __init__(self,name,age,id,salary):
self.name = name
self.age = age
self.salary = salary
self.id = id
def earn(self):
pass
class childemployee1(employee):
def earn(self): //Run-time polymorphism
print("no money")
Example:
26
class childemployee2(employee):
def earn(self):
print("has money")
c = childemployee1
c.earn(employee)
d = childemployee2
d.earn(employee)
Output: no money, has money
27
Abstraction:
Suppose you booked a movie ticket from bookmyshow using
net banking or any other process. You don’t know the
procedure of how the pin is generated or how the verification
is done. This is called ‘abstraction’ from the programming
aspect, it basically means you only show the implementation
details of a particular process and hide the details from the
user.

More Related Content

PPTX
9-_Object_Oriented_Programming_Using_Python 1.pptx
PPTX
9-_Object_Oriented_Programming_Using_Python 1.pptx
PPTX
Object Oriented Programming
PPTX
Presentation_4516_Content_Document_20250204010703PM.pptx
PPTX
Polymorphism.Difference between Inheritance & Polymorphism
PPTX
C++ first s lide
PPTX
Shuvrojit Majumder . 25900120006 Object Oriented Programming (PCC-CS 503) ...
PPTX
Object Oriented Programming in Python
9-_Object_Oriented_Programming_Using_Python 1.pptx
9-_Object_Oriented_Programming_Using_Python 1.pptx
Object Oriented Programming
Presentation_4516_Content_Document_20250204010703PM.pptx
Polymorphism.Difference between Inheritance & Polymorphism
C++ first s lide
Shuvrojit Majumder . 25900120006 Object Oriented Programming (PCC-CS 503) ...
Object Oriented Programming in Python

Similar to 9-_Object_Oriented_Programming_Using_Python.pdf (20)

PPTX
Unit-V.pptx
PPTX
OOP-Advanced Programming with c++
PDF
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
PPTX
Object oriented programming in python
PPTX
C++ programming introduction
PPTX
java oops and java very important for .pptx
PPTX
java oops compilation object class inheritance.pptx
PDF
Polymorphism
PPTX
OOPS 46 slide Python concepts .pptx
PPT
Lecture01
PPT
PPT
PPTX
Php oop (1)
PPTX
Basics of object oriented programming
PDF
Lecture # 02 - OOP with Python Language by Muhammad Haroon
PPTX
Polymorphism in OPP, JAVA, Method overload.pptx
PPTX
Object Oriented Programming Concepts
PPTX
Object Oriented Programming (OOP) Introduction
PPTX
Object Oriented Programming.pptx
PPTX
Introduction to OOPs second year cse.pptx
Unit-V.pptx
OOP-Advanced Programming with c++
Diving in OOP (Day 1) : Polymorphism and Inheritance (Early Binding/Compile T...
Object oriented programming in python
C++ programming introduction
java oops and java very important for .pptx
java oops compilation object class inheritance.pptx
Polymorphism
OOPS 46 slide Python concepts .pptx
Lecture01
Php oop (1)
Basics of object oriented programming
Lecture # 02 - OOP with Python Language by Muhammad Haroon
Polymorphism in OPP, JAVA, Method overload.pptx
Object Oriented Programming Concepts
Object Oriented Programming (OOP) Introduction
Object Oriented Programming.pptx
Introduction to OOPs second year cse.pptx
Ad

More from anaveenkumar4 (14)

PPT
simulation based project presentation matlab Problem background Traditional s...
PPTX
Python Tutorial | Python Programming Language
PPT
04_python_functions.ppt You can define functions to provide the required func...
PDF
Electric circuits are classified in several ways. A direct-current circuit ca...
PPTX
MATLAB UNIT-III.pptx
PPTX
project.pptx
PPT
pump.ppt
PPTX
RET UNIT-4.pptx
PDF
13012-41797-1-RV.pdf
PDF
SolarThermal.pdf
PDF
1-s2.0-S1878029613000716-main.pdf
PPTX
2_Off_Grid_Grid_Tied.pptx
PPTX
TRAINING PROGRAMME ON MATLAB ASSOCIATE EXAM (1).pptx
PPTX
Batch 6.pptx
simulation based project presentation matlab Problem background Traditional s...
Python Tutorial | Python Programming Language
04_python_functions.ppt You can define functions to provide the required func...
Electric circuits are classified in several ways. A direct-current circuit ca...
MATLAB UNIT-III.pptx
project.pptx
pump.ppt
RET UNIT-4.pptx
13012-41797-1-RV.pdf
SolarThermal.pdf
1-s2.0-S1878029613000716-main.pdf
2_Off_Grid_Grid_Tied.pptx
TRAINING PROGRAMME ON MATLAB ASSOCIATE EXAM (1).pptx
Batch 6.pptx
Ad

Recently uploaded (20)

PDF
Votre score augmente si vous choisissez une catégorie et que vous rédigez une...
PPTX
eGramSWARAJ-PPT Training Module for beginners
PPTX
Phase1_final PPTuwhefoegfohwfoiehfoegg.pptx
PPTX
retention in jsjsksksksnbsndjddjdnFPD.pptx
PDF
Session 11 - Data Visualization Storytelling (2).pdf
PPTX
Tapan_20220802057_Researchinternship_final_stage.pptx
PPTX
SET 1 Compulsory MNH machine learning intro
PDF
Jean-Georges Perrin - Spark in Action, Second Edition (2020, Manning Publicat...
PPTX
AI AND ML PROPOSAL PRESENTATION MUST.pptx
PPT
Image processing and pattern recognition 2.ppt
PPTX
Statisticsccdxghbbnhhbvvvvvvvvvv. Dxcvvvhhbdzvbsdvvbbvv ccc
PPTX
MBA JAPAN: 2025 the University of Waseda
PDF
Navigating the Thai Supplements Landscape.pdf
PPTX
Lesson-01intheselfoflifeofthekennyrogersoftheunderstandoftheunderstanded
PDF
Tetra Pak Index 2023 - The future of health and nutrition - Full report.pdf
PDF
©️ 01_Algorithm for Microsoft New Product Launch - handling web site - by Ale...
PDF
OneRead_20250728_1808.pdfhdhddhshahwhwwjjaaja
PPTX
DS-40-Pre-Engagement and Kickoff deck - v8.0.pptx
PDF
Best Data Science Professional Certificates in the USA | IABAC
PPTX
Machine Learning and working of machine Learning
Votre score augmente si vous choisissez une catégorie et que vous rédigez une...
eGramSWARAJ-PPT Training Module for beginners
Phase1_final PPTuwhefoegfohwfoiehfoegg.pptx
retention in jsjsksksksnbsndjddjdnFPD.pptx
Session 11 - Data Visualization Storytelling (2).pdf
Tapan_20220802057_Researchinternship_final_stage.pptx
SET 1 Compulsory MNH machine learning intro
Jean-Georges Perrin - Spark in Action, Second Edition (2020, Manning Publicat...
AI AND ML PROPOSAL PRESENTATION MUST.pptx
Image processing and pattern recognition 2.ppt
Statisticsccdxghbbnhhbvvvvvvvvvv. Dxcvvvhhbdzvbsdvvbbvv ccc
MBA JAPAN: 2025 the University of Waseda
Navigating the Thai Supplements Landscape.pdf
Lesson-01intheselfoflifeofthekennyrogersoftheunderstandoftheunderstanded
Tetra Pak Index 2023 - The future of health and nutrition - Full report.pdf
©️ 01_Algorithm for Microsoft New Product Launch - handling web site - by Ale...
OneRead_20250728_1808.pdfhdhddhshahwhwwjjaaja
DS-40-Pre-Engagement and Kickoff deck - v8.0.pptx
Best Data Science Professional Certificates in the USA | IABAC
Machine Learning and working of machine Learning

9-_Object_Oriented_Programming_Using_Python.pdf

  • 2. 1. Introduction to Object Oriented Programming in Python 2. Difference between object and procedural oriented programming 3. What are Classes and Objects? 4. Object-Oriented Programming methodologies: • Inheritance • Polymorphism • Encapsulation • Abstraction 2 Index
  • 3. 3 1. Introduction to Object Oriented Programming in Python Object Oriented Programming is a way of computer programming using the idea of “objects” to represents data and methods. It is also, an approach used for creating neat and reusable code instead of a redundant one.
  • 4. 2. Difference between Object-Oriented and Procedural Oriented Programming Object-Oriented Programming (OOP) Procedural-Oriented Programming (Pop) It is a bottom-up approach It is a top-down approach Program is divided into objects Program is divided into functions Makes use of Access modifiers ‘public’, private’, protected’ Doesn’t use Access modifiers It is more secure It is less secure Object can move freely within member functions Data can move freely from function to function within programs It supports inheritance It does not support inheritance
  • 5. 5 class class1(): // class 1 is the name of the class A class is a collection of objects or you can say it is a blueprint of objects defining the common attributes and behavior. Now the question arises, how do you do that? Class is defined under a “Class” Keyword. Example: 3. What are Classes and Objects?
  • 6. 6 class employee(): def __init__(self,name,age,id,salary): //creating a function self.name = name // self is an instance of a class self.age = age self.salary = salary self.id = id emp1 = employee("harshit",22,1000,1234) //creating objects emp2 = employee("arjun",23,2000,2234) print(emp1.__dict__)//Prints dictionary Creating an Object and Class in python: Example:
  • 7. 7 ❑ Inheritance ❑ Polymorphism ❑ Encapsulation ❑ Abstraction 4. Object-Oriented Programming methodologies:
  • 8. Inheritance: Ever heard of this dialogue from relatives “you look exactly like your father/mother” the reason behind this is called ‘inheritance’. From the Programming aspect, It generally means “inheriting or transfer of characteristics from parent to child class without any modification”. The new class is called the derived/child class and the one from which it is derived is called a parent/base class.
  • 9. 9
  • 10. Single Inheritance: Single level inheritance enables a derived class to inherit characteristics from a single parent class.
  • 11. class employee1()://This is a parent class def __init__(self, name, age, salary): self.name = name self.age = age self.salary = salary class childemployee(employee1)://This is a child class def __init__(self, name, age, salary,id): self.name = name self.age = age self.salary = salary self.id = id emp1 = employee1('harshit',22,1000) print(emp1.age) Example: Output: 22
  • 12. Multilevel Inheritance: Multi-level inheritance enables a derived class to inherit properties from an immediate parent class which in turn inherits properties from his parent class. class employee()://Super class def __init__(self,name,age,salary): self.name = name self.age = age self.salary = salary class childemployee1(employee)://First child class def __init__(self,name,age,salary): self.name = name self.age = age self.salary = salary Example:
  • 13. class childemployee2(childemployee1)://Second child class def __init__(self, name, age, salary): self.name = name self.age = age self.salary = salary emp1 = employee('harshit',22,1000) emp2 = childemployee1('arjun',23,2000) print(emp1.age) print(emp2.age) Output: 22,23
  • 14. Hierarchical Inheritance: Hierarchical level inheritance enables more than one derived class to inherit properties from a parent class. class employee(): def __init__(self, name, age, salary): //Hierarchical Inheritance self.name = name self.age = age self.salary = salary Example:
  • 15. class childemployee1(employee): def __init__(self,name,age,salary): self.name = name self.age = age self.salary = salary class childemployee2(employee): def __init__(self, name, age, salary): self.name = name self.age = age self.salary = salary emp1 = employee('harshit',22,1000) emp2 = employee('arjun',23,2000)
  • 16. Multiple Inheritance: Multiple level inheritance enables one derived class to inherit properties from more than one base class. class employee1(): //Parent class def __init__(self, name, age, salary): self.name = name self.age = age self.salary = salary Example:
  • 17. class employee2(): //Parent class def __init__(self,name,age,salary,id): self.name = name self.age = age self.salary = salary self.id = id class childemployee(employee1,employee2): def __init__(self, name, age, salary,id): self.name = name self.age = age self.salary = salary self.id = id emp1 = employee1('harshit',22,1000) emp2 = employee2('arjun',23,2000,1234)
  • 18. Polymorphism: You all must have used GPS for navigating the route, Isn’t it amazing how many different routes you come across for the same destination depending on the traffic, from a programming point of view this is called ‘polymorphism’. It is one such OOP methodology where one task can be performed in several different ways. To put it in simple words, it is a property of an object which allows it to take multiple forms.
  • 19. 19
  • 20. 20 Polymorphism is of two types: ❑ Compile-time Polymorphism ❑ Run-time Polymorphism
  • 21. 21 Compile-time Polymorphism: A compile-time polymorphism also called as static polymorphism which gets resolved during the compilation time of the program. One common example is “method overloading”
  • 22. 22 class employee1(): def name(self): print("Harshit is his name") def salary(self): print("3000 is his salary") def age(self): print("22 is his age") class employee2(): def name(self): print("Rahul is his name") def salary(self): print("4000 is his salary") def age(self): print("23 is his age") Example:
  • 23. 23 def func(obj)://Method Overloading obj.name() obj.salary() obj.age() obj_emp1 = employee1() obj_emp2 = employee2() func(obj_emp1) func(obj_emp2) Output: Harshit is his name 3000 is his salary 22 is his age Rahul is his name 4000 is his salary 23 is his age
  • 24. 24 Run-time Polymorphism: A run-time Polymorphism is also, called as dynamic polymorphism where it gets resolved into the run time. One common example of Run-time polymorphism is “method overriding”.
  • 25. 25 class employee(): def __init__(self,name,age,id,salary): self.name = name self.age = age self.salary = salary self.id = id def earn(self): pass class childemployee1(employee): def earn(self): //Run-time polymorphism print("no money") Example:
  • 26. 26 class childemployee2(employee): def earn(self): print("has money") c = childemployee1 c.earn(employee) d = childemployee2 d.earn(employee) Output: no money, has money
  • 27. 27 Abstraction: Suppose you booked a movie ticket from bookmyshow using net banking or any other process. You don’t know the procedure of how the pin is generated or how the verification is done. This is called ‘abstraction’ from the programming aspect, it basically means you only show the implementation details of a particular process and hide the details from the user.