SlideShare a Scribd company logo
Object-Oriented
Programming
(OOP) in python
BAKHAT ALI
Institute of Geoinformatics and Earth Observation,
Pir Mehr Ali Shah Arid Agriculture University Rawalpindi , Punjab, Pakistan
bakhtali21uaar@gmail.com
Object-Oriented Programming
(OOP)
Object-Oriented Programming (OOP) is a programming paradigm that uses
"objects" to encapsulate data and functionality, promoting organized code
and efficient data reuse.
Key Features of OOP
Encapsulation: Protects and bundles data and methods together, ensuring outside interference is
limited.
Abstraction: Simplifies complex systems by exposing only essential features while hiding
unnecessary details.
Inheritance: Allows one class to inherit attributes and behaviors from another, enabling code reuse
and creating a class hierarchy.
Polymorphism: Grants objects the ability to be treated as instances of their parent class, while
allowing their specific implementations to define how actions are executed.
Classes and Objects
Classes
A class is a blueprint to create objects, comprising attributes (data) and
methods (functions).
Objects
An object is an instantiation of a class, representing a specific instance
with defined attributes.
Class and Object Syntax
class ClassName: # Define a class def
__init__(self, param): # Constructor
self.attribute = param # Instance variable
def method_name(self): # Method definition
return self.attribute # Creating an object
(instantiation) object_instance =
ClassName(value)
Example of Class and Object
class Car: def __init__(self, make, model,
year): self.make = make self.model = model
self.year = year def display_info(self):
return f"{self.year} {self.make}
{self.model}" # Instantiating the object
my_car = Car("Toyota", "Corolla", 2021)
print(my_car.display_info()) # Output: 2021
Toyota Corolla
. Inheritance
Inheritance allows one class (child class) to
inherit the properties and methods of
another (parent class).
Types of Inheritance
SINGLE INHERITANCE: A CHILD CLASS INHERITS FROM ONE PARENT
CLASS.
class Animal: def sound(self): return "Some
sound" class Dog(Animal): def sound(self):
return "Bark" dog = Dog()
print(dog.sound()) # Output: Bark
Multilevel Inheritance:
A class inherits from a
derived class.
CLASS PUPPY(DOG): DEF SOUND(SELF): RETURN "YIP"
PUPPY = PUPPY() PRINT(PUPPY.SOUND()) # OUTPUT: YIP
Hierarchical Inheritance: Multiple classes inherit from
one parent class.
class Vehicle: def type(self): return
"Vehicle" class Car(Vehicle): def
type(self): return "Car" class
Bike(Vehicle): def type(self): return
"Bike" car = Car() bike = Bike()
print(car.type()) # Output: Car
print(bike.type()) # Output: Bike
Multiple Inheritance: A class can inherit from multiple parent
classes.
class A: def method_a(self): return "Method
A" class B: def method_b(self): return
"Method B" class C(A, B): def
method_c(self): return "Method C" obj = C()
print(obj.method_a()) # Output: Method A
print(obj.method_b()) # Output: Method B
Polymorphism
POLYMORPHISM ALLOWS METHODS TO DO DIFFERENT THINGS BASED ON THE OBJECT TYPE OR CLASS
INVOKING THEM.
Compile-time Polymorphism (Static Binding):
Achieved mainly through method overloading.
lass Math: def add(self, a, b): return a +
b def add_with_three(self, a, b, c): return
a + b + c math = Math() print(math.add(5,
10)) # Output: 15
print(math.add_with_three(5, 10, 15)) #
Output: 30
Run-time Polymorphism (Dynamic Binding):
Achieved through method overriding.
lass Shape: def area(self): pass class
Rectangle(Shape): def __init__(self,
length, width): self.length = length
self.width = width def area(self): return
self.length * self.width class
Circle(Shape): def __init__(self, radius):
self.radius = radius def area(self): return
3.14 * (self.radius**2) shapes =
[Rectangle(10, 5), Circle(7)] for shape in
shapes: print(shape.area()) # Output: 50,
153.86
Encapsulation
ENCAPSULATION COMBINES ATTRIBUTES AND METHODS IN A CLASS AND RESTRICTS ACCESS USING
ACCESS MODIFIERS.
class BankAccount: def
__init__(self, balance):
self.__balance = balance #
Private attribute def deposit(self,
amount): self.__balance +=
amount def withdraw(self,
amount): if amount <=
self.__balance: self.__balance -=
amount else: print("Insufficient
funds.") def get_balance(self):
return self.__balance account =
BankAccount(1000)
account.deposit(500)
print(account.get_balance()) #
Output: 1500
account.withdraw(200)
print(account.get_balance()) #
Output: 1300
Abstraction
ABSTRACTION SIMPLIFIES COMPLEX SYSTEMS BY HIDING UNNECESSARY DETAILS AND EXPOSING ONLY THE
NECESSARY PARTS USING ABSTRACT CLASSES.
from abc import ABC, abstractmethod class Device(ABC):
@abstractmethod def turn_on(self): pass class
Television(Device): def turn_on(self): return "TV is now ON."
class Radio(Device): def turn_on(self): return "Radio is now
ON." tv = Television() radio = Radio() print(tv.turn_on()) #
Output: TV is now ON. print(radio.turn_on()) # Output: Radio
is now ON.
Comprehensive OOP Features Table with Code Examples
Feature Definition Syntax Example Code Example
Class A blueprint for objects. class ClassName: class Vehicle: pass
Object An instance of a class. object_name = ClassName() my_car = Vehicle()
Attributes Data stored in an object. self.attribute_name = value self.make = "Toyota"
Methods Functions defined inside a class. def method_name(self): def display_info(self): return self.make
Constructor
A method called when an object is
created.
def __init__(self, parameters):
def __init__(self, make, model):
self.make = make
Encapsulation Restricting access to object data.
Use of
underscores: self.__private_data
self.__balance = 1000
Inheritance Deriving new classes from existing ones. class DerivedClass(ParentClass): class Dog(Animal):
Polymorphism
Methods behaving differently based on
the object.
Method Overriding
class Cat(Animal): def sound(self):
return "Meow"
Abstraction Hiding complex implementation details. Use of abstract methods from abc import ABC, abstractmethod
OOP
Summary:
Encapsulation: Protects and bundles
data/functionality.
Abstraction: Simplifies interfaces.
Inheritance: Supports code reuse and
hierarchy.
Polymorphism: Flexible interfaces for
objects.

More Related Content

Similar to Object-Oriented Programming (OO) in pythonP) in python.pptx (20)

object oriented programming(PYTHON)
object oriented programming(PYTHON)object oriented programming(PYTHON)
object oriented programming(PYTHON)
Jyoti shukla
 
arthimetic operator,classes,objects,instant
arthimetic operator,classes,objects,instantarthimetic operator,classes,objects,instant
arthimetic operator,classes,objects,instant
ssuser77162c
 
Python programming computer science and engineering
Python programming computer science and engineeringPython programming computer science and engineering
Python programming computer science and engineering
IRAH34
 
9-_Object_Oriented_Programming_Using_Python 1.pptx
9-_Object_Oriented_Programming_Using_Python 1.pptx9-_Object_Oriented_Programming_Using_Python 1.pptx
9-_Object_Oriented_Programming_Using_Python 1.pptx
Lahari42
 
Presentation_4516_Content_Document_20250204010703PM.pptx
Presentation_4516_Content_Document_20250204010703PM.pptxPresentation_4516_Content_Document_20250204010703PM.pptx
Presentation_4516_Content_Document_20250204010703PM.pptx
MuhammadChala
 
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 Using Python.pdf
Object Oriented programming Using Python.pdfObject Oriented programming Using Python.pdf
Object Oriented programming Using Python.pdf
RishuRaj953240
 
9-_Object_Oriented_Programming_Using_Python.pdf
9-_Object_Oriented_Programming_Using_Python.pdf9-_Object_Oriented_Programming_Using_Python.pdf
9-_Object_Oriented_Programming_Using_Python.pdf
anaveenkumar4
 
Object oriented Programning Lanuagues in text format.
Object oriented Programning Lanuagues in text format.Object oriented Programning Lanuagues in text format.
Object oriented Programning Lanuagues in text format.
SravaniSravani53
 
Problem solving with python programming OOP's Concept
Problem solving with python programming OOP's ConceptProblem solving with python programming OOP's Concept
Problem solving with python programming OOP's Concept
rohitsharma24121
 
OOP concepts -in-Python programming language
OOP concepts -in-Python programming languageOOP concepts -in-Python programming language
OOP concepts -in-Python programming language
SmritiSharma901052
 
OOP in Python, a beginners guide..........
OOP in Python, a beginners guide..........OOP in Python, a beginners guide..........
OOP in Python, a beginners guide..........
FerryKemperman
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
Sujith Kumar
 
Unit – V Object Oriented Programming in Python.pptx
Unit – V Object Oriented Programming in Python.pptxUnit – V Object Oriented Programming in Python.pptx
Unit – V Object Oriented Programming in Python.pptx
YugandharaNalavade
 
Python – Object Oriented Programming
Python – Object Oriented Programming Python – Object Oriented Programming
Python – Object Oriented Programming
Raghunath A
 
Python programming Concepts (Functions, classes and Oops concept
Python programming Concepts (Functions, classes and Oops conceptPython programming Concepts (Functions, classes and Oops concept
Python programming Concepts (Functions, classes and Oops concept
Lipika Sharma
 
Unit - 3.pptx
Unit - 3.pptxUnit - 3.pptx
Unit - 3.pptx
Kongunadu College of Engineering and Technology
 
UNIT 3 PY.pptx - OOPS CONCEPTS IN PYTHON
UNIT 3 PY.pptx - OOPS CONCEPTS IN PYTHONUNIT 3 PY.pptx - OOPS CONCEPTS IN PYTHON
UNIT 3 PY.pptx - OOPS CONCEPTS IN PYTHON
drkangurajuphd
 
Object Oriented Programming.pptx
Object Oriented Programming.pptxObject Oriented Programming.pptx
Object Oriented Programming.pptx
SAICHARANREDDYN
 
Python Programming - Object-Oriented
Python Programming - Object-OrientedPython Programming - Object-Oriented
Python Programming - Object-Oriented
Omid AmirGhiasvand
 
object oriented programming(PYTHON)
object oriented programming(PYTHON)object oriented programming(PYTHON)
object oriented programming(PYTHON)
Jyoti shukla
 
arthimetic operator,classes,objects,instant
arthimetic operator,classes,objects,instantarthimetic operator,classes,objects,instant
arthimetic operator,classes,objects,instant
ssuser77162c
 
Python programming computer science and engineering
Python programming computer science and engineeringPython programming computer science and engineering
Python programming computer science and engineering
IRAH34
 
9-_Object_Oriented_Programming_Using_Python 1.pptx
9-_Object_Oriented_Programming_Using_Python 1.pptx9-_Object_Oriented_Programming_Using_Python 1.pptx
9-_Object_Oriented_Programming_Using_Python 1.pptx
Lahari42
 
Presentation_4516_Content_Document_20250204010703PM.pptx
Presentation_4516_Content_Document_20250204010703PM.pptxPresentation_4516_Content_Document_20250204010703PM.pptx
Presentation_4516_Content_Document_20250204010703PM.pptx
MuhammadChala
 
Object Oriented programming Using Python.pdf
Object Oriented programming Using Python.pdfObject Oriented programming Using Python.pdf
Object Oriented programming Using Python.pdf
RishuRaj953240
 
9-_Object_Oriented_Programming_Using_Python.pdf
9-_Object_Oriented_Programming_Using_Python.pdf9-_Object_Oriented_Programming_Using_Python.pdf
9-_Object_Oriented_Programming_Using_Python.pdf
anaveenkumar4
 
Object oriented Programning Lanuagues in text format.
Object oriented Programning Lanuagues in text format.Object oriented Programning Lanuagues in text format.
Object oriented Programning Lanuagues in text format.
SravaniSravani53
 
Problem solving with python programming OOP's Concept
Problem solving with python programming OOP's ConceptProblem solving with python programming OOP's Concept
Problem solving with python programming OOP's Concept
rohitsharma24121
 
OOP concepts -in-Python programming language
OOP concepts -in-Python programming languageOOP concepts -in-Python programming language
OOP concepts -in-Python programming language
SmritiSharma901052
 
OOP in Python, a beginners guide..........
OOP in Python, a beginners guide..........OOP in Python, a beginners guide..........
OOP in Python, a beginners guide..........
FerryKemperman
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
Sujith Kumar
 
Unit – V Object Oriented Programming in Python.pptx
Unit – V Object Oriented Programming in Python.pptxUnit – V Object Oriented Programming in Python.pptx
Unit – V Object Oriented Programming in Python.pptx
YugandharaNalavade
 
Python – Object Oriented Programming
Python – Object Oriented Programming Python – Object Oriented Programming
Python – Object Oriented Programming
Raghunath A
 
Python programming Concepts (Functions, classes and Oops concept
Python programming Concepts (Functions, classes and Oops conceptPython programming Concepts (Functions, classes and Oops concept
Python programming Concepts (Functions, classes and Oops concept
Lipika Sharma
 
UNIT 3 PY.pptx - OOPS CONCEPTS IN PYTHON
UNIT 3 PY.pptx - OOPS CONCEPTS IN PYTHONUNIT 3 PY.pptx - OOPS CONCEPTS IN PYTHON
UNIT 3 PY.pptx - OOPS CONCEPTS IN PYTHON
drkangurajuphd
 
Object Oriented Programming.pptx
Object Oriented Programming.pptxObject Oriented Programming.pptx
Object Oriented Programming.pptx
SAICHARANREDDYN
 
Python Programming - Object-Oriented
Python Programming - Object-OrientedPython Programming - Object-Oriented
Python Programming - Object-Oriented
Omid AmirGhiasvand
 

More from institute of Geoinformatics and Earth Observation at PMAS ARID Agriculture University of Rawalpindi (15)

Comprehensive Resources Geoinformatics.pptx
Comprehensive  Resources  Geoinformatics.pptxComprehensive  Resources  Geoinformatics.pptx
Comprehensive Resources Geoinformatics.pptx
institute of Geoinformatics and Earth Observation at PMAS ARID Agriculture University of Rawalpindi
 
Bakhat cv making -template free download 2025.docx
Bakhat cv making -template free download 2025.docxBakhat cv making -template free download 2025.docx
Bakhat cv making -template free download 2025.docx
institute of Geoinformatics and Earth Observation at PMAS ARID Agriculture University of Rawalpindi
 
MySQL-A-Comprehensive-Overvie web design w.pptx
MySQL-A-Comprehensive-Overvie web design w.pptxMySQL-A-Comprehensive-Overvie web design w.pptx
MySQL-A-Comprehensive-Overvie web design w.pptx
institute of Geoinformatics and Earth Observation at PMAS ARID Agriculture University of Rawalpindi
 
🌾 Introduction to Agriculture and Residence Patterns 🌍.pptx
🌾 Introduction to Agriculture and Residence Patterns 🌍.pptx🌾 Introduction to Agriculture and Residence Patterns 🌍.pptx
🌾 Introduction to Agriculture and Residence Patterns 🌍.pptx
institute of Geoinformatics and Earth Observation at PMAS ARID Agriculture University of Rawalpindi
 
coordinate systems map projections and graphical and atoms ppt group (B).pptx
coordinate systems map projections and graphical and atoms ppt group (B).pptxcoordinate systems map projections and graphical and atoms ppt group (B).pptx
coordinate systems map projections and graphical and atoms ppt group (B).pptx
institute of Geoinformatics and Earth Observation at PMAS ARID Agriculture University of Rawalpindi
 
flood extent DGKHAN_DIVISION(bakhat ali ).pdf
flood extent  DGKHAN_DIVISION(bakhat ali ).pdfflood extent  DGKHAN_DIVISION(bakhat ali ).pdf
flood extent DGKHAN_DIVISION(bakhat ali ).pdf
institute of Geoinformatics and Earth Observation at PMAS ARID Agriculture University of Rawalpindi
 
Network Analysis using GIS Techniques navigation network mapping for transpor...
Network Analysis using GIS Techniques navigation network mapping for transpor...Network Analysis using GIS Techniques navigation network mapping for transpor...
Network Analysis using GIS Techniques navigation network mapping for transpor...
institute of Geoinformatics and Earth Observation at PMAS ARID Agriculture University of Rawalpindi
 
ppt networks analysis GIS and Remote Sensing.pptx
ppt networks analysis GIS and Remote Sensing.pptxppt networks analysis GIS and Remote Sensing.pptx
ppt networks analysis GIS and Remote Sensing.pptx
institute of Geoinformatics and Earth Observation at PMAS ARID Agriculture University of Rawalpindi
 
Spatial Data Infrastructure (SDI) in GIS and romote sening.pdf
Spatial Data Infrastructure (SDI) in GIS and romote sening.pdfSpatial Data Infrastructure (SDI) in GIS and romote sening.pdf
Spatial Data Infrastructure (SDI) in GIS and romote sening.pdf
institute of Geoinformatics and Earth Observation at PMAS ARID Agriculture University of Rawalpindi
 
Application of Data Structures in GIS and the Purpose of Modeling
Application of Data Structures in GIS and the Purpose of ModelingApplication of Data Structures in GIS and the Purpose of Modeling
Application of Data Structures in GIS and the Purpose of Modeling
institute of Geoinformatics and Earth Observation at PMAS ARID Agriculture University of Rawalpindi
 
webgis PROJECT flood mapping DGKHAN_DIVISION.pptx
webgis PROJECT flood mapping DGKHAN_DIVISION.pptxwebgis PROJECT flood mapping DGKHAN_DIVISION.pptx
webgis PROJECT flood mapping DGKHAN_DIVISION.pptx
institute of Geoinformatics and Earth Observation at PMAS ARID Agriculture University of Rawalpindi
 
ARCGIS-BASED lab geospatial analysis in gis gis.pdf
ARCGIS-BASED lab geospatial  analysis in gis  gis.pdfARCGIS-BASED lab geospatial  analysis in gis  gis.pdf
ARCGIS-BASED lab geospatial analysis in gis gis.pdf
institute of Geoinformatics and Earth Observation at PMAS ARID Agriculture University of Rawalpindi
 
Comprehensive GIS and Remote Sensing Resources ppt final.pptx
Comprehensive GIS and Remote Sensing Resources   ppt final.pptxComprehensive GIS and Remote Sensing Resources   ppt final.pptx
Comprehensive GIS and Remote Sensing Resources ppt final.pptx
institute of Geoinformatics and Earth Observation at PMAS ARID Agriculture University of Rawalpindi
 
Types of maps GIS and romote sening .pdf
Types of maps  GIS and romote sening  .pdfTypes of maps  GIS and romote sening  .pdf
Types of maps GIS and romote sening .pdf
institute of Geoinformatics and Earth Observation at PMAS ARID Agriculture University of Rawalpindi
 
🔍Time Series Analysis LST and UHT Project🔍
🔍Time Series Analysis LST  and UHT Project🔍🔍Time Series Analysis LST  and UHT Project🔍
🔍Time Series Analysis LST and UHT Project🔍
institute of Geoinformatics and Earth Observation at PMAS ARID Agriculture University of Rawalpindi
 
Ad

Recently uploaded (20)

Leveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer IntentsLeveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer Intents
Keheliya Gallaba
 
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdfHow to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
victordsane
 
Best Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small BusinessesBest Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small Businesses
TheTelephony
 
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-OffMicro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Tier1 app
 
COBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM CertificateCOBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM Certificate
VICTOR MAESTRE RAMIREZ
 
Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...
Rishab Acharya
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
Essentials of Resource Planning in a Downturn
Essentials of Resource Planning in a DownturnEssentials of Resource Planning in a Downturn
Essentials of Resource Planning in a Downturn
OnePlan Solutions
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
BradBedford3
 
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdfTop 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Trackobit
 
Revolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management SoftwareRevolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management Software
Insurance Tech Services
 
Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 
Top 5 Task Management Software to Boost Productivity in 2025
Top 5 Task Management Software to Boost Productivity in 2025Top 5 Task Management Software to Boost Productivity in 2025
Top 5 Task Management Software to Boost Productivity in 2025
Orangescrum
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!
PhilMeredith3
 
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdfHow to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
QuickBooks Training
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
Leveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer IntentsLeveraging Foundation Models to Infer Intents
Leveraging Foundation Models to Infer Intents
Keheliya Gallaba
 
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdfHow to purchase, license and subscribe to Microsoft Azure_PDF.pdf
How to purchase, license and subscribe to Microsoft Azure_PDF.pdf
victordsane
 
Best Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small BusinessesBest Inbound Call Tracking Software for Small Businesses
Best Inbound Call Tracking Software for Small Businesses
TheTelephony
 
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-OffMicro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Micro-Metrics Every Performance Engineer Should Validate Before Sign-Off
Tier1 app
 
COBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM CertificateCOBOL Programming with VSCode - IBM Certificate
COBOL Programming with VSCode - IBM Certificate
VICTOR MAESTRE RAMIREZ
 
Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...Online Queue Management System for Public Service Offices [Focused on Municip...
Online Queue Management System for Public Service Offices [Focused on Municip...
Rishab Acharya
 
Artificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across IndustriesArtificial Intelligence Applications Across Industries
Artificial Intelligence Applications Across Industries
SandeepKS52
 
Essentials of Resource Planning in a Downturn
Essentials of Resource Planning in a DownturnEssentials of Resource Planning in a Downturn
Essentials of Resource Planning in a Downturn
OnePlan Solutions
 
iOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod KumariOS Developer Resume 2025 | Pramod Kumar
iOS Developer Resume 2025 | Pramod Kumar
Pramod Kumar
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4Software Engineering Process, Notation & Tools Introduction - Part 4
Software Engineering Process, Notation & Tools Introduction - Part 4
Gaurav Sharma
 
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
Maintaining + Optimizing Database Health: Vendors, Orchestrations, Enrichment...
BradBedford3
 
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdfTop 11 Fleet Management Software Providers in 2025 (2).pdf
Top 11 Fleet Management Software Providers in 2025 (2).pdf
Trackobit
 
Revolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management SoftwareRevolutionize Your Insurance Workflow with Claims Management Software
Revolutionize Your Insurance Workflow with Claims Management Software
Insurance Tech Services
 
Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 
Top 5 Task Management Software to Boost Productivity in 2025
Top 5 Task Management Software to Boost Productivity in 2025Top 5 Task Management Software to Boost Productivity in 2025
Top 5 Task Management Software to Boost Productivity in 2025
Orangescrum
 
Providing Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better DataProviding Better Biodiversity Through Better Data
Providing Better Biodiversity Through Better Data
Safe Software
 
Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!Build enterprise-ready applications using skills you already have!
Build enterprise-ready applications using skills you already have!
PhilMeredith3
 
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdfHow to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
How to Generate Financial Statements in QuickBooks Like a Pro (1).pdf
QuickBooks Training
 
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI SearchAgentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Agentic Techniques in Retrieval-Augmented Generation with Azure AI Search
Maxim Salnikov
 
Ad

Object-Oriented Programming (OO) in pythonP) in python.pptx

  • 1. Object-Oriented Programming (OOP) in python BAKHAT ALI Institute of Geoinformatics and Earth Observation, Pir Mehr Ali Shah Arid Agriculture University Rawalpindi , Punjab, Pakistan [email protected]
  • 2. Object-Oriented Programming (OOP) Object-Oriented Programming (OOP) is a programming paradigm that uses "objects" to encapsulate data and functionality, promoting organized code and efficient data reuse.
  • 3. Key Features of OOP Encapsulation: Protects and bundles data and methods together, ensuring outside interference is limited. Abstraction: Simplifies complex systems by exposing only essential features while hiding unnecessary details. Inheritance: Allows one class to inherit attributes and behaviors from another, enabling code reuse and creating a class hierarchy. Polymorphism: Grants objects the ability to be treated as instances of their parent class, while allowing their specific implementations to define how actions are executed.
  • 4. Classes and Objects Classes A class is a blueprint to create objects, comprising attributes (data) and methods (functions). Objects An object is an instantiation of a class, representing a specific instance with defined attributes.
  • 5. Class and Object Syntax class ClassName: # Define a class def __init__(self, param): # Constructor self.attribute = param # Instance variable def method_name(self): # Method definition return self.attribute # Creating an object (instantiation) object_instance = ClassName(value) Example of Class and Object class Car: def __init__(self, make, model, year): self.make = make self.model = model self.year = year def display_info(self): return f"{self.year} {self.make} {self.model}" # Instantiating the object my_car = Car("Toyota", "Corolla", 2021) print(my_car.display_info()) # Output: 2021 Toyota Corolla
  • 6. . Inheritance Inheritance allows one class (child class) to inherit the properties and methods of another (parent class).
  • 7. Types of Inheritance SINGLE INHERITANCE: A CHILD CLASS INHERITS FROM ONE PARENT CLASS. class Animal: def sound(self): return "Some sound" class Dog(Animal): def sound(self): return "Bark" dog = Dog() print(dog.sound()) # Output: Bark
  • 8. Multilevel Inheritance: A class inherits from a derived class. CLASS PUPPY(DOG): DEF SOUND(SELF): RETURN "YIP" PUPPY = PUPPY() PRINT(PUPPY.SOUND()) # OUTPUT: YIP
  • 9. Hierarchical Inheritance: Multiple classes inherit from one parent class. class Vehicle: def type(self): return "Vehicle" class Car(Vehicle): def type(self): return "Car" class Bike(Vehicle): def type(self): return "Bike" car = Car() bike = Bike() print(car.type()) # Output: Car print(bike.type()) # Output: Bike
  • 10. Multiple Inheritance: A class can inherit from multiple parent classes. class A: def method_a(self): return "Method A" class B: def method_b(self): return "Method B" class C(A, B): def method_c(self): return "Method C" obj = C() print(obj.method_a()) # Output: Method A print(obj.method_b()) # Output: Method B
  • 11. Polymorphism POLYMORPHISM ALLOWS METHODS TO DO DIFFERENT THINGS BASED ON THE OBJECT TYPE OR CLASS INVOKING THEM.
  • 12. Compile-time Polymorphism (Static Binding): Achieved mainly through method overloading. lass Math: def add(self, a, b): return a + b def add_with_three(self, a, b, c): return a + b + c math = Math() print(math.add(5, 10)) # Output: 15 print(math.add_with_three(5, 10, 15)) # Output: 30
  • 13. Run-time Polymorphism (Dynamic Binding): Achieved through method overriding. lass Shape: def area(self): pass class Rectangle(Shape): def __init__(self, length, width): self.length = length self.width = width def area(self): return self.length * self.width class Circle(Shape): def __init__(self, radius): self.radius = radius def area(self): return 3.14 * (self.radius**2) shapes = [Rectangle(10, 5), Circle(7)] for shape in shapes: print(shape.area()) # Output: 50, 153.86
  • 14. Encapsulation ENCAPSULATION COMBINES ATTRIBUTES AND METHODS IN A CLASS AND RESTRICTS ACCESS USING ACCESS MODIFIERS.
  • 15. class BankAccount: def __init__(self, balance): self.__balance = balance # Private attribute def deposit(self, amount): self.__balance += amount def withdraw(self, amount): if amount <= self.__balance: self.__balance -= amount else: print("Insufficient funds.") def get_balance(self): return self.__balance account = BankAccount(1000) account.deposit(500) print(account.get_balance()) # Output: 1500 account.withdraw(200) print(account.get_balance()) # Output: 1300
  • 16. Abstraction ABSTRACTION SIMPLIFIES COMPLEX SYSTEMS BY HIDING UNNECESSARY DETAILS AND EXPOSING ONLY THE NECESSARY PARTS USING ABSTRACT CLASSES.
  • 17. from abc import ABC, abstractmethod class Device(ABC): @abstractmethod def turn_on(self): pass class Television(Device): def turn_on(self): return "TV is now ON." class Radio(Device): def turn_on(self): return "Radio is now ON." tv = Television() radio = Radio() print(tv.turn_on()) # Output: TV is now ON. print(radio.turn_on()) # Output: Radio is now ON.
  • 18. Comprehensive OOP Features Table with Code Examples Feature Definition Syntax Example Code Example Class A blueprint for objects. class ClassName: class Vehicle: pass Object An instance of a class. object_name = ClassName() my_car = Vehicle() Attributes Data stored in an object. self.attribute_name = value self.make = "Toyota" Methods Functions defined inside a class. def method_name(self): def display_info(self): return self.make Constructor A method called when an object is created. def __init__(self, parameters): def __init__(self, make, model): self.make = make Encapsulation Restricting access to object data. Use of underscores: self.__private_data self.__balance = 1000 Inheritance Deriving new classes from existing ones. class DerivedClass(ParentClass): class Dog(Animal): Polymorphism Methods behaving differently based on the object. Method Overriding class Cat(Animal): def sound(self): return "Meow" Abstraction Hiding complex implementation details. Use of abstract methods from abc import ABC, abstractmethod
  • 19. OOP Summary: Encapsulation: Protects and bundles data/functionality. Abstraction: Simplifies interfaces. Inheritance: Supports code reuse and hierarchy. Polymorphism: Flexible interfaces for objects.