SlideShare a Scribd company logo
Object Oriented
Programming
- Python
Agenda
Python
• Introduction
• What is Class
• Inheritance and types
• Polymorphism
• Abstraction
• Encapsulation
2
Introduction
The main concept of OOPs is to bind the data and
the functions that work on that together as a
single unit so that no other part of the code can
access this data.
Python Class
A class is a collection of objects. A class contains the
blueprints or the prototype from which the objects are being
created.
python
3
Class
Syntax of Class:
class ClassName:
# Statement-1
.
# Statement-N
• Classes are created by keyword class.
• Attributes are the variables that belong to a class.
• Attributes are always public and can be accessed using the dot (.) operator.
python
4
Eg: class Dog:
sound = "bark"
…....
Object
• The object is an entity that has a state and behavior associated with it.
• It may be any real-world object like a mouse, keyboard, chair, table, pen, etc.
Integers, strings, floating-point numbers, even arrays, and dictionaries, are all
objects.
• More specifically, any single integer or any single string is an object.
• The number 12 is an object, the string “Hello, world” is an object
python
5
Object
Object Consists of:
• State
• Behavior
• Identity
Example:
• The identity can be considered as the name of the dog.
• State or Attributes can be considered as the breed, age, or color of the dog.
• The behavior can be considered as to whether the dog is eating or sleeping.
python
6
Constructors and Destructors
Constructors
• Used for instantiating an object.
• The task of constructors is to initialize(assign values)
to the data members of the class when an object of
the class is created.
• In Python the __init__() method is called the
constructor and is always called when an object is
created.
Syntax of constructor declaration :
def __init__(self):
# body of the constructor
Types:
Default Parameterized constructor
Destructors
• Destructors are called when an object gets destroyed.
• In Python, destructors are not needed as much as in C++ because
Python has a garbage collector that handles memory management
automatically.
• The __del__() method is a known as a destructor method in Python.
It is called when all references to the object have been deleted i.e
when an object is garbage collected.
Syntax of destructor declaration :
def __del__(self):
# body of destructor
7
Oops Concepts
• Inheritance
• Polymorphism
• Abstraction
• Encapsulation
Python
8
Inheritance
Inheritance is defined as the mechanism of inheriting
the properties of the base class to the child class
The Parent class is the class which provides features
to another class. The parent class is also known
as Base class or Superclass.
The Child class is the class which receives features
from another class. The child class is also known as
the Derived Class or Subclass.
Python
9
Types of Inheritance
• Single
• Multiple
• Multilevel
• Hierarchical
• Hybrid
Single Inheritance
Single inheritance enables a derived class to
inherit properties from a single parent class.
10
PYTHON
Multiple Inheritance
• A class can be derived from more than one base class
this type of inheritance is called multiple inheritances.
• In multiple inheritances, all the features of the base
classes are inherited into the derived class.
11
PYTHON
Multilevel Inheritance
• In multilevel inheritance, features of the base class
and the derived class are further inherited into the
new derived class.
• This is similar to a relationship representing a
child and a grandfather.
12
PYTHON
Hierarchical Inheritance
• When more than one derived class are created from a
single base this type of inheritance is called hierarchical
inheritance.
• In this program, we have a parent (base) class and two or
more child(derived) classes.
13
PYTHON
Hybrid Inheritance
• Inheritance consisting of multiple
types of inheritance is called
hybrid inheritance.
14
PYTHON
Polymorphism
• Polymorphism simply means having many forms.
• This code demonstrates the concept of inheritance
and method overriding in Python classes.
• It shows how subclasses can override methods
defined in their parent class to provide specific
behavior while still inheriting other methods from
the parent class.
15
PYTHON
Encapsulation
• Encapsulation is a mechanism of wrapping the data (variables) and
code acting on the data (methods) together as a single unit.
• Access modifiers in the concept of Encapsulation and data hiding.
• Public: Accessible from inside or outside the class.
• Private: Accessible only inside class. Define a private member by
prefixing the member name with two underscores. Eg: __age
• Protected: Accessible. from inside the class and its sub-class.
Define a protected member by prefixing the member name with an
underscore Eg: _points
16
Access Modifiers
•Public
•Private
•Protected
Abstraction
• It hides unnecessary code details from the user.
• Also, when we do not want to give out sensitive
parts of our code implementation and this is where
data abstraction came.
17
Python
SUMMARY
Python
• These are various Object Oriented Programming
concepts in Python.
• Online Reference:
W3schools
GeeksforGeeks
18
Thank You
Any Queries ??

More Related Content

PPTX
arthimetic operator,classes,objects,instant
PPTX
Object Oriented Programming.pptx
PDF
Unit 3-Classes ,Objects and Inheritance.pdf
PPTX
Class and Objects in python programming.pptx
PPTX
oop.pptx
PPTX
Python programming Concepts (Functions, classes and Oops concept
PPTX
PYTHON OBJECT-ORIENTED PROGRAMMING.pptx
PPTX
Object Oriented Programming Tutorial.pptx
arthimetic operator,classes,objects,instant
Object Oriented Programming.pptx
Unit 3-Classes ,Objects and Inheritance.pdf
Class and Objects in python programming.pptx
oop.pptx
Python programming Concepts (Functions, classes and Oops concept
PYTHON OBJECT-ORIENTED PROGRAMMING.pptx
Object Oriented Programming Tutorial.pptx

Similar to Object-Oriented Programming System presentation (20)

PPTX
Lecture-10_PHP-OOP.pptx
PPTX
Object oriented programming 6 oop with c++
PPTX
Object Oriented Programming Class and Objects
PPSX
OOPS Concepts in Python and Exception Handling
PPTX
Lecture 5.pptx
PPTX
python1 object oriented programming.pptx
PPTX
Principles and advantages of oop ppt
PPTX
PPTX
Introduction to OOP concepts
PPT
Object -oriented analysis and design.ppt
PPTX
Object oriented programming
PPTX
Object Oriented Programming - Copy.pptxb
PPTX
Oopsinphp
PDF
PythonOO.pdf oo Object Oriented programming
PPTX
Php oop (1)
PPTX
Introduction to oop and java fundamentals
PPTX
Introduction to OOP with java
PPTX
An overview of Object Oriented Programming in C#.
PPTX
basic concepts of object oriented in python
Lecture-10_PHP-OOP.pptx
Object oriented programming 6 oop with c++
Object Oriented Programming Class and Objects
OOPS Concepts in Python and Exception Handling
Lecture 5.pptx
python1 object oriented programming.pptx
Principles and advantages of oop ppt
Introduction to OOP concepts
Object -oriented analysis and design.ppt
Object oriented programming
Object Oriented Programming - Copy.pptxb
Oopsinphp
PythonOO.pdf oo Object Oriented programming
Php oop (1)
Introduction to oop and java fundamentals
Introduction to OOP with java
An overview of Object Oriented Programming in C#.
basic concepts of object oriented in python
Ad

Recently uploaded (20)

PDF
Pre independence Education in Inndia.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Institutional Correction lecture only . . .
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
Classroom Observation Tools for Teachers
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Insiders guide to clinical Medicine.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pre independence Education in Inndia.pdf
Supply Chain Operations Speaking Notes -ICLT Program
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Microbial disease of the cardiovascular and lymphatic systems
Abdominal Access Techniques with Prof. Dr. R K Mishra
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Institutional Correction lecture only . . .
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Complications of Minimal Access Surgery at WLH
Classroom Observation Tools for Teachers
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Insiders guide to clinical Medicine.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
O7-L3 Supply Chain Operations - ICLT Program
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Ad

Object-Oriented Programming System presentation

  • 2. Agenda Python • Introduction • What is Class • Inheritance and types • Polymorphism • Abstraction • Encapsulation 2
  • 3. Introduction The main concept of OOPs is to bind the data and the functions that work on that together as a single unit so that no other part of the code can access this data. Python Class A class is a collection of objects. A class contains the blueprints or the prototype from which the objects are being created. python 3
  • 4. Class Syntax of Class: class ClassName: # Statement-1 . # Statement-N • Classes are created by keyword class. • Attributes are the variables that belong to a class. • Attributes are always public and can be accessed using the dot (.) operator. python 4 Eg: class Dog: sound = "bark" …....
  • 5. Object • The object is an entity that has a state and behavior associated with it. • It may be any real-world object like a mouse, keyboard, chair, table, pen, etc. Integers, strings, floating-point numbers, even arrays, and dictionaries, are all objects. • More specifically, any single integer or any single string is an object. • The number 12 is an object, the string “Hello, world” is an object python 5
  • 6. Object Object Consists of: • State • Behavior • Identity Example: • The identity can be considered as the name of the dog. • State or Attributes can be considered as the breed, age, or color of the dog. • The behavior can be considered as to whether the dog is eating or sleeping. python 6
  • 7. Constructors and Destructors Constructors • Used for instantiating an object. • The task of constructors is to initialize(assign values) to the data members of the class when an object of the class is created. • In Python the __init__() method is called the constructor and is always called when an object is created. Syntax of constructor declaration : def __init__(self): # body of the constructor Types: Default Parameterized constructor Destructors • Destructors are called when an object gets destroyed. • In Python, destructors are not needed as much as in C++ because Python has a garbage collector that handles memory management automatically. • The __del__() method is a known as a destructor method in Python. It is called when all references to the object have been deleted i.e when an object is garbage collected. Syntax of destructor declaration : def __del__(self): # body of destructor 7
  • 8. Oops Concepts • Inheritance • Polymorphism • Abstraction • Encapsulation Python 8
  • 9. Inheritance Inheritance is defined as the mechanism of inheriting the properties of the base class to the child class The Parent class is the class which provides features to another class. The parent class is also known as Base class or Superclass. The Child class is the class which receives features from another class. The child class is also known as the Derived Class or Subclass. Python 9 Types of Inheritance • Single • Multiple • Multilevel • Hierarchical • Hybrid
  • 10. Single Inheritance Single inheritance enables a derived class to inherit properties from a single parent class. 10 PYTHON
  • 11. Multiple Inheritance • A class can be derived from more than one base class this type of inheritance is called multiple inheritances. • In multiple inheritances, all the features of the base classes are inherited into the derived class. 11 PYTHON
  • 12. Multilevel Inheritance • In multilevel inheritance, features of the base class and the derived class are further inherited into the new derived class. • This is similar to a relationship representing a child and a grandfather. 12 PYTHON
  • 13. Hierarchical Inheritance • When more than one derived class are created from a single base this type of inheritance is called hierarchical inheritance. • In this program, we have a parent (base) class and two or more child(derived) classes. 13 PYTHON
  • 14. Hybrid Inheritance • Inheritance consisting of multiple types of inheritance is called hybrid inheritance. 14 PYTHON
  • 15. Polymorphism • Polymorphism simply means having many forms. • This code demonstrates the concept of inheritance and method overriding in Python classes. • It shows how subclasses can override methods defined in their parent class to provide specific behavior while still inheriting other methods from the parent class. 15 PYTHON
  • 16. Encapsulation • Encapsulation is a mechanism of wrapping the data (variables) and code acting on the data (methods) together as a single unit. • Access modifiers in the concept of Encapsulation and data hiding. • Public: Accessible from inside or outside the class. • Private: Accessible only inside class. Define a private member by prefixing the member name with two underscores. Eg: __age • Protected: Accessible. from inside the class and its sub-class. Define a protected member by prefixing the member name with an underscore Eg: _points 16 Access Modifiers •Public •Private •Protected
  • 17. Abstraction • It hides unnecessary code details from the user. • Also, when we do not want to give out sensitive parts of our code implementation and this is where data abstraction came. 17 Python
  • 18. SUMMARY Python • These are various Object Oriented Programming concepts in Python. • Online Reference: W3schools GeeksforGeeks 18