Python OOPs
Concepts
Copyright Intellipaat. All rights reserved.
Agenda
01 Constructors 02 Inheritance
03 Abstraction 04 Encapsulation
05 Polymorphism
Copyright Intellipaat. All rights reserved.
Python Constructors
Constructors in object oriented
programming paradigm are used to
instantiate the objects. Usually with the
same name as the class, a constructor gets
called as soon as the object is created.
Copyright Intellipaat. All rights reserved.
Python Constructors
In python, __init__() method is the default
constructor that gets called as soon as the
object is created for the class.
Copyright Intellipaat. All rights reserved.
Python Constructors
The parameterized constructor will have
parameters in the constructor as shown in
the example.
Copyright Intellipaat. All rights reserved.
Python Inheritance
Inheritance is an object oriented
programming concept in which one or more
classes inherit the properties from a parent
class, just like how a family hierarchy will
have characteristics from the their
respective parents.
Copyright Intellipaat. All rights reserved.
Python Inheritance
There are mainly 4 types of inheritance.
Single Inheritance
Multiple inheritance
Multilevel Inheritance Hierarchical Inheritance
Copyright Intellipaat. All rights reserved.
Python Inheritance
In Single Inheritance, only one child class
inherits from the parent class.
Base Class
Child Class
Copyright Intellipaat. All rights reserved.
Python Inheritance
In multilevel inheritance, Child class inherits
from the parent class and then the child class
becomes a parent class for another child class.
Base Class
Child Class
Child Class 2
Copyright Intellipaat. All rights reserved.
Python Inheritance
In multiple inheritance, the child class inherits
from more than one base class.
Base Class 1 Base Class 2
Child Class 2
Copyright Intellipaat. All rights reserved.
Python Inheritance
In hierarchical inheritance, more than one child class inherits from the base class.
Copyright Intellipaat. All rights reserved.
Python Abstraction
Abstraction is an Object oriented
programming concept that ensures that the
internal functioning is hidden from the
users. i.e the user knows what the code
does, but not how it’s being done.
Copyright Intellipaat. All rights reserved.
Python Abstraction
To implement abstraction in python, we
create an abstract class from the abc
module. The abstract class cannot have an
object, therefore the child classes will
inherit the abstract method to implement
abstraction in python.
Copyright Intellipaat. All rights reserved.
Python Abstraction
Method Overriding Concrete Methods
Copyright Intellipaat. All rights reserved.
Encapsulation in Python
Encapsulation is an Object oriented concept
that can be summarized as “wrapping up of
data in single unit”.
Copyright Intellipaat. All rights reserved.
Encapsulation in Python
Public class members are The protected members
The private members will
accessible outside the class will be accessed within the
be restricted to only within
as well as by the derived class and by the derived
the class.
class. class.
Copyright Intellipaat. All rights reserved.
Encapsulation in Python
Encapsulation in python is the implementation
where the access is restricted for the class
members through private and protected access
modifiers.
The derived class is able to access the protected
member from the Parent class, but it will not be
able to access the private member by
convention.
Copyright Intellipaat. All rights reserved.
Polymorphism in Python
Polymorphism is an Object oriented concept
that assures that the data can be displayed
in more than one forms.
Copyright Intellipaat. All rights reserved.
Polymorphism in Python
The method Area is used for
different implementations
for both child and parent
class.
Copyright Intellipaat. All rights reserved.