SlideShare a Scribd company logo
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
OBJECT ORIENTED PROGRAMMING
WITH PYTHON
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
LET’S DISCUSS
 Why OOPs
 Classes & Objects
 Inheritance
 Revisiting Types & Exceptions
 Polymorphism
 Operator Overloading
 Method Overriding
 Quick Quiz
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
THE CURRENT SCENARIO
Let’s store employee data
Why OOPs
# Ask for the name of the employee
name = input("Enter the name of the employee: ")
# Ask for the age of the employee
age = input("Enter the age of the employee: ")
# Print the collected information
print(f"Employee Name: {name}")
print(f"Employee Age: {age}")
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
LET’S IMPROVE IT
# Function to input employee data (name and age)
def input_employee_data():
name = input("Enter the name of the employee: ")
age = input("Enter the age of the employee: ")
return name, age
# Function to print employee information
def print_employee_info(name, age):
print(f"Employee Name: {name}")
print(f"Employee Age: {age}")
name, age = input_employee_data()
print_employee_info(name, age)
# Ask for the name of the employee
name = input("Enter the name of the employee: ")
# Ask for the age of the employee
age = input("Enter the age of the employee: ")
# Print the collected information
print(f"Employee Name: {name}")
print(f"Employee Age: {age}")
Why OOPs
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
IS THAT GOOD ENOUGH?
# Function to input employee data (name and age)
def input_employee_data():
name = input("Enter the name of the employee: ")
age = input("Enter the age of the employee: ")
return name, age
# Function to print employee information
def print_employee_info(name, age):
print(f"Employee Name: {name}")
print(f"Employee Age: {age}")
name, age = input_employee_data()
print_employee_info(name, age)
Why OOPs
class Employee:
def input_employee_data(self):
self.name = input("Enter the name of the employee: ")
self.age = input("Enter the age of the employee: ")
def print_employee_info(self):
print(f"Employee Name: {self.name}")
print(f"Employee Age: {self.age}")
# Create an instance of the Employee class
employee = Employee()
# Input employee data using the class method
employee.input_employee_data()
# Print employee information using the class method
employee.print_employee_info()
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
PARADIGMS OF PROGRAMMING
# Ask for the name of the employee
name = input("Enter the name : ")
# Ask for the age of the employee
age = input("Enter the age of the employee: ")
# Print the collected information
print(f"Employee Name: {name}")
print(f"Employee Age: {age}")
# Function to input employee data (name and age)
def input_employee_data():
name = input("Enter the name of the employee: ")
age = input("Enter the age of the employee: ")
return name, age
# Function to print employee information
def print_employee_info(name, age):
print(f"Employee Name: {name}")
print(f"Employee Age: {age}")
name, age = input_employee_data()
print_employee_info(name, age)
class Employee:
def input_employee_data(self):
self.name = input("Enter the name of the employee: ")
self.age = input("Enter the age of the employee: ")
def print_employee_info(self):
print(f"Employee Name: {self.name}")
print(f"Employee Age: {self.age}")
# Create an instance of the Employee class
employee = Employee()
# Input employee data using the class method
employee.input_employee_data()
# Print employee information using the class method
employee.print_employee_info()
Procedural Functional Object Oriented
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
CLASSES
Classes are used to create our
own type of data and give them
names.
Classes are “Blueprints”
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
OBJECTS
Any time you
create a class and
you utilize that
“blueprint” to
create “object”.
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
CLASSES AND OBJECTS IN ACTION
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
CLASSES AND OBJECTS IN ACTION
class Employee:
def input_employee_data(self):
self.name = input("Enter the name of the employee: ")
self.age = input("Enter the age of the employee: ")
def print_employee_info(self):
print(f"Employee Name: {self.name}")
print(f"Employee Age: {self.age}")
# Create an instance of the Employee class
employee1 = Employee()
# Create another instance of the Employee
class
employee2 = Employee()
# Yet another instance of the Employee class
employee3 = Employee()
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
ANATOMY OF A CLASS
class Employee:
...
Class is a
Blueprint
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
METHODS IN CLASS
# Create an instance of the Employee class
employee = Employee()
# Input employee data using the class method
employee.input_employee_data()
class Employee:
def input_employee_data(self):
self.name = input("Enter the name of the employee: ")
self.age = input("Enter the age of the employee: ")
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
WHAT IS “self”
class Employee:
def input_employee_data(self):
self.name = input("Enter the name of the employee: ")
self.age = input("Enter the age of the employee: ")
self refers to the current object that was just created.
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
ATTRIBUTES
class Employee:
def input_employee_data(self):
self.name = input("Enter the name of the employee: ")
self.age = input("Enter the age of the employee: ")
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
SET ATTRIBUTES WHILE CREATING THE OBJECT
class Employee:
def input_employee_data(self):
self.name = input("Enter the name of the employee: ")
self.age = input("Enter the age of the employee: ")
# Driver Code
# Create an instance of the Employee class
employee = Employee()
# Input employee data using the class method
employee.input_employee_data()
class Employee:
def __init__(self, name, age):
self.name = name
self.age = age
# Driver Code
name = input("Enter the name of the employee: ")
age = input("Enter the age of the employee: ")
# Create an instance of the Employee class
employee = Employee(name, age)
# Print the employee data
print("Employee Name:", employee.name)
print("Employee Age:", employee.age)
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
LET’S VISUALISE __init__()
class Employee:
def __init__(self, name, age):
self.name = name
self.age = age
self.name
self.age
name
age
# Create an instance
employee = Employee(name, age)
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
WHERE ARE THESE EMPLOYEE WORKING?
class Employee:
org = 'CompanyName'
def input_employee_data(self):
self.name = input("Enter the name of the employee: ")
self.age = input("Enter the age of the employee: ")
def print_employee_info(self):
print(f"Employee Name: {self.name}")
print(f"Employee Age: {self.age}")
emp = Employee()
print(emp.org)
Class Variables
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
WHAT ABOUT CODE REUSABILITY?
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
INHERITENCE
class Human:
...
class Employee:
...
class Human:
...
class Employee(Human):
...
Inheritance enables us
to create a class that
“inherits” methods,
variables, and attributes
from another class.
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
INHERITENCE IN ACTION
class Human:
def __init__(self, height):
self.height = height
class Employee(Human):
def __init__(self, height, name, age):
super().__init__(height)
self.name = name
self.age = age
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
YOU ARE ALREADY USING CLASSES
https://docs.python.org/3/library/stdtypes.html#str
surprise
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
EXCEPTIONS
BaseException
+-- KeyboardInterrupt
+-- Exception
+-- ArithmeticError
| +-- ZeroDivisionError
+-- AssertionError
+-- AttributeError
+-- EOFError
+-- ImportError
| +-- ModuleNotFoundError
+-- LookupError
| +-- KeyError
+-- NameError
+-- SyntaxError
| +-- IndentationError
+-- ValueError
...
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
POLYMORPHISM
 Poly – many
 Morph - shapes
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
OPERATOR OVERLOADING
 Some operators such as
+ and - can be
“overloaded” such that
they can have more
abilities beyond simple
arithmetic.
class MyNumber:
def __init__(self, num=0):
self.num = num
def __add__(self, other):
return self.num * other.num
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
HOW IT WORKED?
 We override the __add__ method
 https://docs.python.org/3/reference/datamod
el.html?highlight=__add__#object.__add__
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
METHOD OVERRIDING
class Human:
def __init__(self, name, age):
self.name = name
self.age = age
def introduce(self):
print(f"Hello, I am {self.name} and I am {self.age} years old.")
class Employee(Human):
def __init__(self, name, age, employee_id):
super().__init__(name, age)
self.employee_id = employee_id
# Method overriding
def introduce(self):
print(f"Hello, I am {self.name}, an employee with ID {self.employee_id}.")
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
QUIZ TIME
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
THANKS

More Related Content

Similar to Object Oriented Programming in Python (20)

Having issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdfHaving issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdf
rajkumarm401
 
Final Presentation V1.8
Final Presentation V1.8Final Presentation V1.8
Final Presentation V1.8
Chad Koziel
 
HOW TO CREATE A MODULE IN ODOO
HOW TO CREATE A MODULE IN ODOOHOW TO CREATE A MODULE IN ODOO
HOW TO CREATE A MODULE IN ODOO
Celine George
 
structure and union
structure and unionstructure and union
structure and union
student
 
Programming Primer Encapsulation CS
Programming Primer Encapsulation CSProgramming Primer Encapsulation CS
Programming Primer Encapsulation CS
sunmitraeducation
 
Structure and union
Structure and unionStructure and union
Structure and union
Samsil Arefin
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
Muhammed Thanveer M
 
CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces  CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces
HomeWork-Fox
 
python.pdf
python.pdfpython.pdf
python.pdf
SwapnilGujar10
 
2. Create a Java class called EmployeeMain within the same project Pr.docx
 2. Create a Java class called EmployeeMain within the same project Pr.docx 2. Create a Java class called EmployeeMain within the same project Pr.docx
2. Create a Java class called EmployeeMain within the same project Pr.docx
ajoy21
 
I am trying to change this code from STRUCTS to CLASSES, the members.pdf
I am trying to change this code from STRUCTS to CLASSES, the members.pdfI am trying to change this code from STRUCTS to CLASSES, the members.pdf
I am trying to change this code from STRUCTS to CLASSES, the members.pdf
petercoiffeur18
 
Written by Dr. Preiser 1 CIS 3100 MS Access Assignment .docx
Written by Dr. Preiser 1 CIS 3100 MS Access Assignment  .docxWritten by Dr. Preiser 1 CIS 3100 MS Access Assignment  .docx
Written by Dr. Preiser 1 CIS 3100 MS Access Assignment .docx
troutmanboris
 
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Celine George
 
Sencha Touch - Introduction
Sencha Touch - IntroductionSencha Touch - Introduction
Sencha Touch - Introduction
ABC-GROEP.BE
 
Form demoinplaywithmysql
Form demoinplaywithmysqlForm demoinplaywithmysql
Form demoinplaywithmysql
Knoldus Inc.
 
How to Show Sample Data in Tree and Kanban View in Odoo 17
How to Show Sample Data in Tree and Kanban View in Odoo 17How to Show Sample Data in Tree and Kanban View in Odoo 17
How to Show Sample Data in Tree and Kanban View in Odoo 17
Celine George
 
Django Admin: Widgetry & Witchery
Django Admin: Widgetry & WitcheryDjango Admin: Widgetry & Witchery
Django Admin: Widgetry & Witchery
Pamela Fox
 
Presentation_4516_Content_Document_20250204010703PM.pptx
Presentation_4516_Content_Document_20250204010703PM.pptxPresentation_4516_Content_Document_20250204010703PM.pptx
Presentation_4516_Content_Document_20250204010703PM.pptx
MuhammadChala
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
Maulik Borsaniya
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
Rai University
 
Having issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdfHaving issues with passing my values through different functions aft.pdf
Having issues with passing my values through different functions aft.pdf
rajkumarm401
 
Final Presentation V1.8
Final Presentation V1.8Final Presentation V1.8
Final Presentation V1.8
Chad Koziel
 
HOW TO CREATE A MODULE IN ODOO
HOW TO CREATE A MODULE IN ODOOHOW TO CREATE A MODULE IN ODOO
HOW TO CREATE A MODULE IN ODOO
Celine George
 
structure and union
structure and unionstructure and union
structure and union
student
 
Programming Primer Encapsulation CS
Programming Primer Encapsulation CSProgramming Primer Encapsulation CS
Programming Primer Encapsulation CS
sunmitraeducation
 
Oop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer MelayiOop concept in c++ by MUhammed Thanveer Melayi
Oop concept in c++ by MUhammed Thanveer Melayi
Muhammed Thanveer M
 
CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces  CIS 247C iLab 4 of 7: Composition and Class Interfaces
CIS 247C iLab 4 of 7: Composition and Class Interfaces
HomeWork-Fox
 
2. Create a Java class called EmployeeMain within the same project Pr.docx
 2. Create a Java class called EmployeeMain within the same project Pr.docx 2. Create a Java class called EmployeeMain within the same project Pr.docx
2. Create a Java class called EmployeeMain within the same project Pr.docx
ajoy21
 
I am trying to change this code from STRUCTS to CLASSES, the members.pdf
I am trying to change this code from STRUCTS to CLASSES, the members.pdfI am trying to change this code from STRUCTS to CLASSES, the members.pdf
I am trying to change this code from STRUCTS to CLASSES, the members.pdf
petercoiffeur18
 
Written by Dr. Preiser 1 CIS 3100 MS Access Assignment .docx
Written by Dr. Preiser 1 CIS 3100 MS Access Assignment  .docxWritten by Dr. Preiser 1 CIS 3100 MS Access Assignment  .docx
Written by Dr. Preiser 1 CIS 3100 MS Access Assignment .docx
troutmanboris
 
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Celine George
 
Sencha Touch - Introduction
Sencha Touch - IntroductionSencha Touch - Introduction
Sencha Touch - Introduction
ABC-GROEP.BE
 
Form demoinplaywithmysql
Form demoinplaywithmysqlForm demoinplaywithmysql
Form demoinplaywithmysql
Knoldus Inc.
 
How to Show Sample Data in Tree and Kanban View in Odoo 17
How to Show Sample Data in Tree and Kanban View in Odoo 17How to Show Sample Data in Tree and Kanban View in Odoo 17
How to Show Sample Data in Tree and Kanban View in Odoo 17
Celine George
 
Django Admin: Widgetry & Witchery
Django Admin: Widgetry & WitcheryDjango Admin: Widgetry & Witchery
Django Admin: Widgetry & Witchery
Pamela Fox
 
Presentation_4516_Content_Document_20250204010703PM.pptx
Presentation_4516_Content_Document_20250204010703PM.pptxPresentation_4516_Content_Document_20250204010703PM.pptx
Presentation_4516_Content_Document_20250204010703PM.pptx
MuhammadChala
 
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAPYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
Maulik Borsaniya
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
Rai University
 

Recently uploaded (20)

Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
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
 
Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3
Gaurav Sharma
 
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
 
14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework
Angelo Theodorou
 
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
 
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
Insurance Tech Services
 
Who will create the languages of the future?
Who will create the languages of the future?Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
FME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable InsightsFME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable Insights
Safe Software
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
AI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA TechnologiesAI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA Technologies
SandeepKS52
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
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
 
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
 
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
 
Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 
Automating Map Production With FME and Python
Automating Map Production With FME and PythonAutomating Map Production With FME and Python
Automating Map Production With FME and Python
Safe Software
 
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentricIntegration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Natan Silnitsky
 
Migrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right WayMigrating to Azure Cosmos DB the Right Way
Migrating to Azure Cosmos DB the Right Way
Alexander (Alex) Komyagin
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your wayPlooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
Generative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its ApplicationsGenerative Artificial Intelligence and its Applications
Generative Artificial Intelligence and its Applications
SandeepKS52
 
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
 
Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3Software Engineering Process, Notation & Tools Introduction - Part 3
Software Engineering Process, Notation & Tools Introduction - Part 3
Gaurav Sharma
 
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
 
14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework14 Years of Developing nCine - An Open Source 2D Game Framework
14 Years of Developing nCine - An Open Source 2D Game Framework
Angelo Theodorou
 
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
 
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
How Insurance Policy Administration Streamlines Policy Lifecycle for Agile Op...
Insurance Tech Services
 
Who will create the languages of the future?
Who will create the languages of the future?Who will create the languages of the future?
Who will create the languages of the future?
Jordi Cabot
 
FME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable InsightsFME for Climate Data: Turning Big Data into Actionable Insights
FME for Climate Data: Turning Big Data into Actionable Insights
Safe Software
 
GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?GDG Douglas - Google AI Agents: Your Next Intern?
GDG Douglas - Google AI Agents: Your Next Intern?
felipeceotto
 
AI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA TechnologiesAI and Deep Learning with NVIDIA Technologies
AI and Deep Learning with NVIDIA Technologies
SandeepKS52
 
Key AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence CompaniesKey AI Technologies Used by Indian Artificial Intelligence Companies
Key AI Technologies Used by Indian Artificial Intelligence Companies
Mypcot Infotech
 
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
 
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
 
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
 
Agile Software Engineering Methodologies
Agile Software Engineering MethodologiesAgile Software Engineering Methodologies
Agile Software Engineering Methodologies
Gaurav Sharma
 
Automating Map Production With FME and Python
Automating Map Production With FME and PythonAutomating Map Production With FME and Python
Automating Map Production With FME and Python
Safe Software
 
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentricIntegration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Integration Ignited Redefining Event-Driven Architecture at Wix - EventCentric
Natan Silnitsky
 
Plooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your wayPlooma is a writing platform to plan, write, and shape books your way
Plooma is a writing platform to plan, write, and shape books your way
Plooma
 
Ad

Object Oriented Programming in Python

  • 1. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. OBJECT ORIENTED PROGRAMMING WITH PYTHON
  • 2. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. LET’S DISCUSS  Why OOPs  Classes & Objects  Inheritance  Revisiting Types & Exceptions  Polymorphism  Operator Overloading  Method Overriding  Quick Quiz
  • 3. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. THE CURRENT SCENARIO Let’s store employee data Why OOPs # Ask for the name of the employee name = input("Enter the name of the employee: ") # Ask for the age of the employee age = input("Enter the age of the employee: ") # Print the collected information print(f"Employee Name: {name}") print(f"Employee Age: {age}")
  • 4. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. LET’S IMPROVE IT # Function to input employee data (name and age) def input_employee_data(): name = input("Enter the name of the employee: ") age = input("Enter the age of the employee: ") return name, age # Function to print employee information def print_employee_info(name, age): print(f"Employee Name: {name}") print(f"Employee Age: {age}") name, age = input_employee_data() print_employee_info(name, age) # Ask for the name of the employee name = input("Enter the name of the employee: ") # Ask for the age of the employee age = input("Enter the age of the employee: ") # Print the collected information print(f"Employee Name: {name}") print(f"Employee Age: {age}") Why OOPs
  • 5. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. IS THAT GOOD ENOUGH? # Function to input employee data (name and age) def input_employee_data(): name = input("Enter the name of the employee: ") age = input("Enter the age of the employee: ") return name, age # Function to print employee information def print_employee_info(name, age): print(f"Employee Name: {name}") print(f"Employee Age: {age}") name, age = input_employee_data() print_employee_info(name, age) Why OOPs class Employee: def input_employee_data(self): self.name = input("Enter the name of the employee: ") self.age = input("Enter the age of the employee: ") def print_employee_info(self): print(f"Employee Name: {self.name}") print(f"Employee Age: {self.age}") # Create an instance of the Employee class employee = Employee() # Input employee data using the class method employee.input_employee_data() # Print employee information using the class method employee.print_employee_info()
  • 6. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. PARADIGMS OF PROGRAMMING # Ask for the name of the employee name = input("Enter the name : ") # Ask for the age of the employee age = input("Enter the age of the employee: ") # Print the collected information print(f"Employee Name: {name}") print(f"Employee Age: {age}") # Function to input employee data (name and age) def input_employee_data(): name = input("Enter the name of the employee: ") age = input("Enter the age of the employee: ") return name, age # Function to print employee information def print_employee_info(name, age): print(f"Employee Name: {name}") print(f"Employee Age: {age}") name, age = input_employee_data() print_employee_info(name, age) class Employee: def input_employee_data(self): self.name = input("Enter the name of the employee: ") self.age = input("Enter the age of the employee: ") def print_employee_info(self): print(f"Employee Name: {self.name}") print(f"Employee Age: {self.age}") # Create an instance of the Employee class employee = Employee() # Input employee data using the class method employee.input_employee_data() # Print employee information using the class method employee.print_employee_info() Procedural Functional Object Oriented
  • 7. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. CLASSES Classes are used to create our own type of data and give them names. Classes are “Blueprints”
  • 8. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. OBJECTS Any time you create a class and you utilize that “blueprint” to create “object”.
  • 9. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. CLASSES AND OBJECTS IN ACTION
  • 10. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. CLASSES AND OBJECTS IN ACTION class Employee: def input_employee_data(self): self.name = input("Enter the name of the employee: ") self.age = input("Enter the age of the employee: ") def print_employee_info(self): print(f"Employee Name: {self.name}") print(f"Employee Age: {self.age}") # Create an instance of the Employee class employee1 = Employee() # Create another instance of the Employee class employee2 = Employee() # Yet another instance of the Employee class employee3 = Employee()
  • 11. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. ANATOMY OF A CLASS class Employee: ... Class is a Blueprint
  • 12. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. METHODS IN CLASS # Create an instance of the Employee class employee = Employee() # Input employee data using the class method employee.input_employee_data() class Employee: def input_employee_data(self): self.name = input("Enter the name of the employee: ") self.age = input("Enter the age of the employee: ")
  • 13. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. WHAT IS “self” class Employee: def input_employee_data(self): self.name = input("Enter the name of the employee: ") self.age = input("Enter the age of the employee: ") self refers to the current object that was just created.
  • 14. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. ATTRIBUTES class Employee: def input_employee_data(self): self.name = input("Enter the name of the employee: ") self.age = input("Enter the age of the employee: ")
  • 15. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. SET ATTRIBUTES WHILE CREATING THE OBJECT class Employee: def input_employee_data(self): self.name = input("Enter the name of the employee: ") self.age = input("Enter the age of the employee: ") # Driver Code # Create an instance of the Employee class employee = Employee() # Input employee data using the class method employee.input_employee_data() class Employee: def __init__(self, name, age): self.name = name self.age = age # Driver Code name = input("Enter the name of the employee: ") age = input("Enter the age of the employee: ") # Create an instance of the Employee class employee = Employee(name, age) # Print the employee data print("Employee Name:", employee.name) print("Employee Age:", employee.age)
  • 16. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. LET’S VISUALISE __init__() class Employee: def __init__(self, name, age): self.name = name self.age = age self.name self.age name age # Create an instance employee = Employee(name, age)
  • 17. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. WHERE ARE THESE EMPLOYEE WORKING? class Employee: org = 'CompanyName' def input_employee_data(self): self.name = input("Enter the name of the employee: ") self.age = input("Enter the age of the employee: ") def print_employee_info(self): print(f"Employee Name: {self.name}") print(f"Employee Age: {self.age}") emp = Employee() print(emp.org) Class Variables
  • 18. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. WHAT ABOUT CODE REUSABILITY?
  • 19. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. INHERITENCE class Human: ... class Employee: ... class Human: ... class Employee(Human): ... Inheritance enables us to create a class that “inherits” methods, variables, and attributes from another class.
  • 20. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. INHERITENCE IN ACTION class Human: def __init__(self, height): self.height = height class Employee(Human): def __init__(self, height, name, age): super().__init__(height) self.name = name self.age = age
  • 21. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. YOU ARE ALREADY USING CLASSES https://docs.python.org/3/library/stdtypes.html#str surprise
  • 22. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. EXCEPTIONS BaseException +-- KeyboardInterrupt +-- Exception +-- ArithmeticError | +-- ZeroDivisionError +-- AssertionError +-- AttributeError +-- EOFError +-- ImportError | +-- ModuleNotFoundError +-- LookupError | +-- KeyError +-- NameError +-- SyntaxError | +-- IndentationError +-- ValueError ...
  • 23. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. POLYMORPHISM  Poly – many  Morph - shapes
  • 24. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. OPERATOR OVERLOADING  Some operators such as + and - can be “overloaded” such that they can have more abilities beyond simple arithmetic. class MyNumber: def __init__(self, num=0): self.num = num def __add__(self, other): return self.num * other.num
  • 25. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. HOW IT WORKED?  We override the __add__ method  https://docs.python.org/3/reference/datamod el.html?highlight=__add__#object.__add__
  • 26. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. METHOD OVERRIDING class Human: def __init__(self, name, age): self.name = name self.age = age def introduce(self): print(f"Hello, I am {self.name} and I am {self.age} years old.") class Employee(Human): def __init__(self, name, age, employee_id): super().__init__(name, age) self.employee_id = employee_id # Method overriding def introduce(self): print(f"Hello, I am {self.name}, an employee with ID {self.employee_id}.")
  • 27. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. QUIZ TIME
  • 28. BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only. THANKS