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}")
Ad
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()
Ad
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”
Ad
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
Ad
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
Ad
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.
Ad
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)
Ad
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
Ad
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.
Ad
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
Ad
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
Ad
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__
Ad
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
Ad
BUSINESS DOCUMENT This document is intended for business use and should be distributed to intended recipients only.
THANKS
Ad

More Related Content

Similar to Object Oriented Programming in Python (20)

PDF
Having issues with passing my values through different functions aft.pdf
10 slides4 views
PPTX
Final Presentation V1.8
22 slides232 views
PPTX
HOW TO CREATE A MODULE IN ODOO
35 slides815 views
PPT
structure and union
41 slides19.5K views
PPTX
Programming Primer Encapsulation CS
15 slides54 views
PPT
Structure and union
43 slides745 views
PPTX
Oop concept in c++ by MUhammed Thanveer Melayi
18 slides690 views
DOCX
CIS 247C iLab 4 of 7: Composition and Class Interfaces
4 slides742 views
PDF
python.pdf
15 slides58 views
DOCX
2. Create a Java class called EmployeeMain within the same project Pr.docx
6 slides45 views
PDF
I am trying to change this code from STRUCTS to CLASSES, the members.pdf
8 slides17 views
DOCX
Written by Dr. Preiser 1 CIS 3100 MS Access Assignment .docx
47 slides65 views
PPTX
Creation or Update of a Mandatory Field is Not Set in Odoo 17
10 slides941 views
PPTX
Sencha Touch - Introduction
60 slides1.1K views
PPT
Form demoinplaywithmysql
31 slides13.2K views
PPTX
How to Show Sample Data in Tree and Kanban View in Odoo 17
7 slides739 views
KEY
Django Admin: Widgetry & Witchery
16 slides2.3K views
PPTX
Presentation_4516_Content_Document_20250204010703PM.pptx
39 slides23 views
PDF
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
24 slides2.9K views
PPT
pointer, structure ,union and intro to file handling
41 slides3K views
Having issues with passing my values through different functions aft.pdf
10 slides4 views
Final Presentation V1.8
22 slides232 views
HOW TO CREATE A MODULE IN ODOO
35 slides815 views
structure and union
41 slides19.5K views
Programming Primer Encapsulation CS
15 slides54 views
Structure and union
43 slides745 views
Oop concept in c++ by MUhammed Thanveer Melayi
18 slides690 views
CIS 247C iLab 4 of 7: Composition and Class Interfaces
4 slides742 views
python.pdf
15 slides58 views
2. Create a Java class called EmployeeMain within the same project Pr.docx
6 slides45 views
I am trying to change this code from STRUCTS to CLASSES, the members.pdf
8 slides17 views
Written by Dr. Preiser 1 CIS 3100 MS Access Assignment .docx
47 slides65 views
Creation or Update of a Mandatory Field is Not Set in Odoo 17
10 slides941 views
Sencha Touch - Introduction
60 slides1.1K views
Form demoinplaywithmysql
31 slides13.2K views
How to Show Sample Data in Tree and Kanban View in Odoo 17
7 slides739 views
Django Admin: Widgetry & Witchery
16 slides2.3K views
Presentation_4516_Content_Document_20250204010703PM.pptx
39 slides23 views
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYA
24 slides2.9K views
pointer, structure ,union and intro to file handling
41 slides3K views

Recently uploaded (20)

PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
6 slides29 views
PPTX
Transform Your Business with a Software ERP System
9 slides43 views
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
17 slides38 views
PDF
PTS Company Brochure 2025 (1).pdf.......
32 slides246 views
PPTX
Odoo POS Development Services by CandidRoot Solutions
PPTX
Essential Infomation Tech presentation.pptx
48 slides22 views
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
24 slides42 views
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
19 slides73 views
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
13 slides39 views
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Softaken Excel to vCard Converter Software.pdf
9 slides28 views
PDF
AI in Product Development-omnex systems
7 slides36 views
PDF
Understanding Forklifts - TECH EHS Solution
7 slides47 views
PDF
How Creative Agencies Leverage Project Management Software.pdf
7 slides32 views
PDF
Nekopoi APK 2025 free lastest update
67 slides184 views
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
3 slides30 views
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
10 slides32 views
PDF
Design an Analysis of Algorithms II-SECS-1021-03
76 slides33 views
PPTX
history of c programming in notes for students .pptx
2 slides22 views
PDF
Odoo Companies in India – Driving Business Transformation.pdf
13 slides37 views
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
6 slides29 views
Transform Your Business with a Software ERP System
9 slides43 views
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
17 slides38 views
PTS Company Brochure 2025 (1).pdf.......
32 slides246 views
Odoo POS Development Services by CandidRoot Solutions
Essential Infomation Tech presentation.pptx
48 slides22 views
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
24 slides42 views
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
19 slides73 views
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
13 slides39 views
Reimagine Home Health with the Power of Agentic AI​
Softaken Excel to vCard Converter Software.pdf
9 slides28 views
AI in Product Development-omnex systems
7 slides36 views
Understanding Forklifts - TECH EHS Solution
7 slides47 views
How Creative Agencies Leverage Project Management Software.pdf
7 slides32 views
Nekopoi APK 2025 free lastest update
67 slides184 views
Which alternative to Crystal Reports is best for small or large businesses.pdf
3 slides30 views
Wondershare Filmora 15 Crack With Activation Key [2025
10 slides32 views
Design an Analysis of Algorithms II-SECS-1021-03
76 slides33 views
history of c programming in notes for students .pptx
2 slides22 views
Odoo Companies in India – Driving Business Transformation.pdf
13 slides37 views
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