0% found this document useful (0 votes)
2 views10 pages

Lec-5 Inheritance in Python

The document explains the concept of inheritance in Python, describing classes as blueprints for creating objects with attributes and methods. It covers the use of the 'self' parameter, the initialization method, and the four pillars of Object-Oriented Programming (OOP): Abstraction, Encapsulation, Polymorphism, and Inheritance. Inheritance allows a child class to inherit attributes and methods from a parent class while also enabling the child class to define its own attributes and methods.

Uploaded by

sarakshiithorat
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views10 pages

Lec-5 Inheritance in Python

The document explains the concept of inheritance in Python, describing classes as blueprints for creating objects with attributes and methods. It covers the use of the 'self' parameter, the initialization method, and the four pillars of Object-Oriented Programming (OOP): Abstraction, Encapsulation, Polymorphism, and Inheritance. Inheritance allows a child class to inherit attributes and methods from a parent class while also enabling the child class to define its own attributes and methods.

Uploaded by

sarakshiithorat
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Let 5 Inheritance in Python

class A template or blueprint for creating


objects It has attributes and methods
that the objects can access

Eg class car
Max speed 140
engine type petrol

type sedan

object An instance of the class

It can have its own attributes apart


from the of class
attribute and have
access to the methods of class to which
it belongs

Eg Creta Carl
creta type Suv
Creta color white
self parameter
It is as an extra parameter when
given
a method is defined in a class
It is use to alcess the variables of the

class

EG

def show_detail self

print car has max speed of self max speed


print car is of self type type
Creta Carl
Creta type sun

creta show_detail
Car has max speed of 140
car is of sun type
i

def show_detail self color

print car has max speed of self max speed


print car is of self type type
print color of car is color

creta Carl
creta type Suv
Creta show_detail white

init 11
initialization method
Each time object is created this
an
method is called automatically
Main purpose is to assign attribute
values to the
object at the time they
are created
[Link] Arjun
studentgrade A

Lut 9799in is in B
30years old
Hello my name is Alice and I am

Hello name is Kim and I am 23 years07


my
Al current counter 2
current counter 2

1B current counter 5
Current counter 2

2 2 tnt o c current counter 5


range 1,61 1.213,415 current counter 5

Clocount 5 D current counter 2


To C2count current counter 5
C2 count 2
To

Pillars of OOPS

1 Abstraction It hides complex implementation


details and show
only what is necessary
Encapsulation Bundling data attributes and methods
that operate on data into a
single unit
It restricts direct access to some of
Object's attributes and method

Polymorphism It allows the same method to


be used across diff object types

Inheritance
Here one class child class derived class sub class
inherits the attributes and methods from another
class parent class Base class super class
In addition child class can have its own
attributes and methods
Child class can also redefine the method of
its parent class
Inheritance allows the reuse of the existing code

syntax
A method A

B method A
method B
I
method A
method D
method C

EI

You might also like