SlideShare a Scribd company logo
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

PDF
Python programming : Inheritance and polymorphism
PPTX
Object oriented programming with python
PPTX
Object Oriented Programming Principles
PDF
Object oriented approach in python programming
PPTX
Abstract Base Class and Polymorphism in C++
PPTX
Object Oriented Programming in Python
PPSX
Files in c++
PPTX
Basic Python Programming: Part 01 and Part 02
Python programming : Inheritance and polymorphism
Object oriented programming with python
Object Oriented Programming Principles
Object oriented approach in python programming
Abstract Base Class and Polymorphism in C++
Object Oriented Programming in Python
Files in c++
Basic Python Programming: Part 01 and Part 02

What's hot (20)

PPTX
Functions in Python
PPTX
Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion |
PPTX
Basic data structures in python
PDF
Python's magic methods
PPTX
CLASS OBJECT AND INHERITANCE IN PYTHON
PDF
Function in Python
PDF
Python Programming - Files & Exceptions
PPT
Php with MYSQL Database
PPTX
Functions in Python
PPTX
USER DEFINE FUNCTIONS IN PYTHON
PDF
004 - JavaFX Tutorial - Event Handling
PDF
Graphics Programming in C under GNU Linux (Ubuntu distribution)
PDF
Python Class | Python Programming | Python Tutorial | Edureka
PPTX
PHP Functions & Arrays
PPT
16 virtual function
PPTX
File Handling Python
PDF
Python Generators
PDF
Data Types In PHP
PPTX
Python Tutorial Part 1
Functions in Python
Python Programming | JNTUA | UNIT 2 | Conditionals and Recursion |
Basic data structures in python
Python's magic methods
CLASS OBJECT AND INHERITANCE IN PYTHON
Function in Python
Python Programming - Files & Exceptions
Php with MYSQL Database
Functions in Python
USER DEFINE FUNCTIONS IN PYTHON
004 - JavaFX Tutorial - Event Handling
Graphics Programming in C under GNU Linux (Ubuntu distribution)
Python Class | Python Programming | Python Tutorial | Edureka
PHP Functions & Arrays
16 virtual function
File Handling Python
Python Generators
Data Types In PHP
Python Tutorial Part 1
Ad

Similar to Object Oriented programming Using Python.pdf (20)

PPTX
9-_Object_Oriented_Programming_Using_Python 1.pptx
PPTX
Presentation_4516_Content_Document_20250204010703PM.pptx
PDF
Lecture # 02 - OOP with Python Language by Muhammad Haroon
PDF
Unit 3-Classes ,Objects and Inheritance.pdf
PPTX
OOP concepts -in-Python programming language
PPTX
Python advance
PPTX
Python programming computer science and engineering
PPTX
object oriented programming(PYTHON)
PPTX
Class and Objects in python programming.pptx
PPTX
Inheritance
PPTX
Problem solving with python programming OOP's Concept
PPT
Python session 7 by Shan
PPTX
Python Lecture 13
PDF
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PPTX
OOP Concepts Python with code refrences.pptx
PDF
Object Oriented Programming in Python
PPTX
Introduction to OOP_Python_Lecture1.pptx
PPTX
PDF
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
9-_Object_Oriented_Programming_Using_Python 1.pptx
Presentation_4516_Content_Document_20250204010703PM.pptx
Lecture # 02 - OOP with Python Language by Muhammad Haroon
Unit 3-Classes ,Objects and Inheritance.pdf
OOP concepts -in-Python programming language
Python advance
Python programming computer science and engineering
object oriented programming(PYTHON)
Class and Objects in python programming.pptx
Inheritance
Problem solving with python programming OOP's Concept
Python session 7 by Shan
Python Lecture 13
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
OOP Concepts Python with code refrences.pptx
Object Oriented Programming in Python
Introduction to OOP_Python_Lecture1.pptx
اسلاید جلسه ۹ کلاس پایتون برای هکر های قانونی
Ad

More from RishuRaj953240 (11)

PPTX
milankovitch cycle.pptx
PPTX
Unit 1 (2) (1).pptx
PPTX
Unit I_dany (1).pptx
PDF
UNIT 1.pdf
PDF
UNIT 1 SRMIST KTR_problem and agents.pdf
PDF
ADE ALL UNITS.pdf
PDF
Unit 3.pdf
PDF
Important question.pdf
PDF
graph-theory-Slides.pdf
PPTX
PNP.pptx
PDF
BOD&COD.pdf
milankovitch cycle.pptx
Unit 1 (2) (1).pptx
Unit I_dany (1).pptx
UNIT 1.pdf
UNIT 1 SRMIST KTR_problem and agents.pdf
ADE ALL UNITS.pdf
Unit 3.pdf
Important question.pdf
graph-theory-Slides.pdf
PNP.pptx
BOD&COD.pdf

Recently uploaded (20)

PPTX
meets orient on the new industry intereacting skills .pptx
PPTX
24AI201_AI_Unit_4 (1).pptx Artificial intelligence
PPT
Chapter 6 Design in software Engineeing.ppt
PPTX
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
PPT
Ppt for engineering students application on field effect
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
Ship’s Structural Components.pptx 7.7 Mb
PPTX
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
PDF
July 2025: Top 10 Read Articles Advanced Information Technology
PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
ETO & MEO Certificate of Competency Questions and Answers
PDF
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
PDF
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
PDF
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
PPTX
AgentX UiPath Community Webinar series - Delhi
PPTX
Chapter----five---Resource Recovery.pptx
PDF
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
PPTX
TE-AI-Unit VI notes using planning model
meets orient on the new industry intereacting skills .pptx
24AI201_AI_Unit_4 (1).pptx Artificial intelligence
Chapter 6 Design in software Engineeing.ppt
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
Ppt for engineering students application on field effect
Lesson 3_Tessellation.pptx finite Mathematics
Ship’s Structural Components.pptx 7.7 Mb
Unit 5 BSP.pptxytrrftyyydfyujfttyczcgvcd
July 2025: Top 10 Read Articles Advanced Information Technology
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
ETO & MEO Certificate of Competency Questions and Answers
Monitoring Global Terrestrial Surface Water Height using Remote Sensing - ARS...
A Framework for Securing Personal Data Shared by Users on the Digital Platforms
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
AgentX UiPath Community Webinar series - Delhi
Chapter----five---Resource Recovery.pptx
Geotechnical Engineering, Soil mechanics- Soil Testing.pdf
TE-AI-Unit VI notes using planning model

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.