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

Similar to 9-_Object_Oriented_Programming_Using_Python.pdf

C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
sandeep54552
 
java oops compilation object class inheritance.pptx
java oops compilation object class inheritance.pptxjava oops compilation object class inheritance.pptx
java oops compilation object class inheritance.pptx
CHERUKURIYUVARAJU209
 
Lecture01
Lecture01Lecture01
Lecture01
artgreen
 
Seminar
SeminarSeminar
SEMINAR
SEMINARSEMINAR
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
Sudip Simkhada
 
Basics of object oriented programming
Basics of object oriented programmingBasics of object oriented programming
Basics of object oriented programming
Nitin Kumar Kashyap
 
Lecture # 02 - OOP with Python Language by Muhammad Haroon
Lecture # 02 - OOP with Python Language by Muhammad HaroonLecture # 02 - OOP with Python Language by Muhammad Haroon
Lecture # 02 - OOP with Python Language by Muhammad Haroon
National College of Business Administration & Economics ( NCBA&E)
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
SanmatiRM
 
Object Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionObject Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) Introduction
SamuelAnsong6
 
Object Oriented Programming.pptx
 Object Oriented Programming.pptx Object Oriented Programming.pptx
Object Oriented Programming.pptx
ShuvrojitMajumder
 
Object Oriented Programming Overview for the PeopleSoft Developer
Object Oriented Programming Overview for the PeopleSoft DeveloperObject Oriented Programming Overview for the PeopleSoft Developer
Object Oriented Programming Overview for the PeopleSoft Developer
Lee Greffin
 
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptxOBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
Maharshi Dayanand University Rohtak
 
Object oriented programing
Object oriented programingObject oriented programing
Object oriented programing
Jamaluddin Malakzai
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
ilias ahmed
 
Chapter8:Understanding Polymorphism
Chapter8:Understanding PolymorphismChapter8:Understanding Polymorphism
Chapter8:Understanding Polymorphism
It Academy
 
1669609053088_oops_final.pptx
1669609053088_oops_final.pptx1669609053088_oops_final.pptx
1669609053088_oops_final.pptx
PandeeswariKannan
 
oopsinvb-191021101327.pdf
oopsinvb-191021101327.pdfoopsinvb-191021101327.pdf
oopsinvb-191021101327.pdf
JP Chicano
 
Oops in vb
Oops in vbOops in vb
Oops in vb
Dalwin INDIA
 

Similar to 9-_Object_Oriented_Programming_Using_Python.pdf (20)

C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
 
java oops compilation object class inheritance.pptx
java oops compilation object class inheritance.pptxjava oops compilation object class inheritance.pptx
java oops compilation object class inheritance.pptx
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Lecture01
Lecture01Lecture01
Lecture01
 
Seminar
SeminarSeminar
Seminar
 
SEMINAR
SEMINARSEMINAR
SEMINAR
 
Php oop (1)
Php oop (1)Php oop (1)
Php oop (1)
 
Basics of object oriented programming
Basics of object oriented programmingBasics of object oriented programming
Basics of object oriented programming
 
Lecture # 02 - OOP with Python Language by Muhammad Haroon
Lecture # 02 - OOP with Python Language by Muhammad HaroonLecture # 02 - OOP with Python Language by Muhammad Haroon
Lecture # 02 - OOP with Python Language by Muhammad Haroon
 
Object Oriented Programming Concepts
Object Oriented Programming ConceptsObject Oriented Programming Concepts
Object Oriented Programming Concepts
 
Object Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) IntroductionObject Oriented Programming (OOP) Introduction
Object Oriented Programming (OOP) Introduction
 
Object Oriented Programming.pptx
 Object Oriented Programming.pptx Object Oriented Programming.pptx
Object Oriented Programming.pptx
 
Object Oriented Programming Overview for the PeopleSoft Developer
Object Oriented Programming Overview for the PeopleSoft DeveloperObject Oriented Programming Overview for the PeopleSoft Developer
Object Oriented Programming Overview for the PeopleSoft Developer
 
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptxOBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
OBJECT ORIENTED PROGRAMMING CONCEPTS IN C++.pptx
 
Object oriented programing
Object oriented programingObject oriented programing
Object oriented programing
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
 
Chapter8:Understanding Polymorphism
Chapter8:Understanding PolymorphismChapter8:Understanding Polymorphism
Chapter8:Understanding Polymorphism
 
1669609053088_oops_final.pptx
1669609053088_oops_final.pptx1669609053088_oops_final.pptx
1669609053088_oops_final.pptx
 
oopsinvb-191021101327.pdf
oopsinvb-191021101327.pdfoopsinvb-191021101327.pdf
oopsinvb-191021101327.pdf
 
Oops in vb
Oops in vbOops in vb
Oops in vb
 

More from anaveenkumar4

Python Tutorial | Python Programming Language
Python Tutorial | Python Programming LanguagePython Tutorial | Python Programming Language
Python Tutorial | Python Programming Language
anaveenkumar4
 
04_python_functions.ppt You can define functions to provide the required func...
04_python_functions.ppt You can define functions to provide the required func...04_python_functions.ppt You can define functions to provide the required func...
04_python_functions.ppt You can define functions to provide the required func...
anaveenkumar4
 
Electric circuits are classified in several ways. A direct-current circuit ca...
Electric circuits are classified in several ways. A direct-current circuit ca...Electric circuits are classified in several ways. A direct-current circuit ca...
Electric circuits are classified in several ways. A direct-current circuit ca...
anaveenkumar4
 
MATLAB UNIT-III.pptx
MATLAB UNIT-III.pptxMATLAB UNIT-III.pptx
MATLAB UNIT-III.pptx
anaveenkumar4
 
project.pptx
project.pptxproject.pptx
project.pptx
anaveenkumar4
 
pump.ppt
pump.pptpump.ppt
pump.ppt
anaveenkumar4
 
RET UNIT-4.pptx
RET UNIT-4.pptxRET UNIT-4.pptx
RET UNIT-4.pptx
anaveenkumar4
 
13012-41797-1-RV.pdf
13012-41797-1-RV.pdf13012-41797-1-RV.pdf
13012-41797-1-RV.pdf
anaveenkumar4
 
SolarThermal.pdf
SolarThermal.pdfSolarThermal.pdf
SolarThermal.pdf
anaveenkumar4
 
1-s2.0-S1878029613000716-main.pdf
1-s2.0-S1878029613000716-main.pdf1-s2.0-S1878029613000716-main.pdf
1-s2.0-S1878029613000716-main.pdf
anaveenkumar4
 
2_Off_Grid_Grid_Tied.pptx
2_Off_Grid_Grid_Tied.pptx2_Off_Grid_Grid_Tied.pptx
2_Off_Grid_Grid_Tied.pptx
anaveenkumar4
 
TRAINING PROGRAMME ON MATLAB ASSOCIATE EXAM (1).pptx
TRAINING PROGRAMME ON MATLAB  ASSOCIATE EXAM (1).pptxTRAINING PROGRAMME ON MATLAB  ASSOCIATE EXAM (1).pptx
TRAINING PROGRAMME ON MATLAB ASSOCIATE EXAM (1).pptx
anaveenkumar4
 
Batch 6.pptx
Batch 6.pptxBatch 6.pptx
Batch 6.pptx
anaveenkumar4
 

More from anaveenkumar4 (13)

Python Tutorial | Python Programming Language
Python Tutorial | Python Programming LanguagePython Tutorial | Python Programming Language
Python Tutorial | Python Programming Language
 
04_python_functions.ppt You can define functions to provide the required func...
04_python_functions.ppt You can define functions to provide the required func...04_python_functions.ppt You can define functions to provide the required func...
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...
Electric circuits are classified in several ways. A direct-current circuit ca...Electric circuits are classified in several ways. A direct-current circuit ca...
Electric circuits are classified in several ways. A direct-current circuit ca...
 
MATLAB UNIT-III.pptx
MATLAB UNIT-III.pptxMATLAB UNIT-III.pptx
MATLAB UNIT-III.pptx
 
project.pptx
project.pptxproject.pptx
project.pptx
 
pump.ppt
pump.pptpump.ppt
pump.ppt
 
RET UNIT-4.pptx
RET UNIT-4.pptxRET UNIT-4.pptx
RET UNIT-4.pptx
 
13012-41797-1-RV.pdf
13012-41797-1-RV.pdf13012-41797-1-RV.pdf
13012-41797-1-RV.pdf
 
SolarThermal.pdf
SolarThermal.pdfSolarThermal.pdf
SolarThermal.pdf
 
1-s2.0-S1878029613000716-main.pdf
1-s2.0-S1878029613000716-main.pdf1-s2.0-S1878029613000716-main.pdf
1-s2.0-S1878029613000716-main.pdf
 
2_Off_Grid_Grid_Tied.pptx
2_Off_Grid_Grid_Tied.pptx2_Off_Grid_Grid_Tied.pptx
2_Off_Grid_Grid_Tied.pptx
 
TRAINING PROGRAMME ON MATLAB ASSOCIATE EXAM (1).pptx
TRAINING PROGRAMME ON MATLAB  ASSOCIATE EXAM (1).pptxTRAINING PROGRAMME ON MATLAB  ASSOCIATE EXAM (1).pptx
TRAINING PROGRAMME ON MATLAB ASSOCIATE EXAM (1).pptx
 
Batch 6.pptx
Batch 6.pptxBatch 6.pptx
Batch 6.pptx
 

Recently uploaded

一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单
ocavb
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
Tabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflowsTabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflows
alex933524
 
一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单
enxupq
 
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
vcaxypu
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Subhajit Sahu
 
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdfSample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Linda486226
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
TravisMalana
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
enxupq
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
ewymefz
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
AbhimanyuSinha9
 
Empowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptxEmpowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptx
benishzehra469
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
nscud
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
NABLAS株式会社
 
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
haila53
 
社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .
NABLAS株式会社
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
John Andrews
 
Q1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year ReboundQ1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year Rebound
Oppotus
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
yhkoc
 

Recently uploaded (20)

一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
Tabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflowsTabula.io Cheatsheet: automate your data workflows
Tabula.io Cheatsheet: automate your data workflows
 
一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单
 
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
一比一原版(ArtEZ毕业证)ArtEZ艺术学院毕业证成绩单
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
 
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdfSample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
 
Empowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptxEmpowering Data Analytics Ecosystem.pptx
Empowering Data Analytics Ecosystem.pptx
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
 
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
【社内勉強会資料_Octo: An Open-Source Generalist Robot Policy】
 
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdfCh03-Managing the Object-Oriented Information Systems Project a.pdf
Ch03-Managing the Object-Oriented Information Systems Project a.pdf
 
社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
 
Q1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year ReboundQ1’2024 Update: MYCI’s Leap Year Rebound
Q1’2024 Update: MYCI’s Leap Year Rebound
 
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
一比一原版(CU毕业证)卡尔顿大学毕业证成绩单
 

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.