Inheritance in Python
Inheritance in Python
PROJECT REPORT
ON
“INHERITANCE IN PYTHON”
1
Inheritance in Python
CERTIFICATE
This is to certify that Project Report entitled “INHERITANCE IN PYTHON”
with reference to SNBP college of Arts, commerce, science and Management
studies, Morwadi, Pimpri, Pune-18 which is being submitted here with the
completion of Bachelor of Business Administration (Computer Application) of
Semester V of Savitribai Phule Pune University is the result of the original work
completed by Mr. PRASHANT SUDHAKAR LAMB (BC213018) and Mr.
GURUDATTA KAMBLE (BC213014) under my supervision and guidance and
to the best of my knowledge and belief, the work complied in this project report
is original & not formed earlier.
Verified By
Seat No. Date:
2
Inheritance in Python
ACKNOWLEDGEMENT
Sincerely,
-Prashant Sudhakar Lamb
-Gurudatta Kamble
T.Y.BBA (CA)
3
Inheritance in Python
Declaration
It is hereby declared the all the facts and figures included
in the project is results of my own research and investigation
including formal analysis of the entire research work and the
same has not been previously submitted to any examination of
the University or any other University.
This declaration will hold a good and in my wise behalf
with the full consciousness.
Date:
Place: Morwadi
4
Inheritance in Python
CONTENTS
SR NO. Chapter name and Page No.
contents
02 Classes 7
03 Inheritance 8
04 Object class 10
05 Types of 12
inheritance
5
Inheritance in Python
Chapter 1
CLASS And OBJECTS IN PYTHON
Class creates a user-defined data structure, which holds its own data
members and member functions, which can be accessed and used by
creating an instance of that class. A class is like a blueprint for an
object.
6
Inheritance in Python
CHAPTER 2
CLASSES
7
Inheritance in Python
CHAPTER 3
INHERITANCE
Inheritance is the capability of one class to derive or inherit the
properties from another class. The benefits of inheritance are:
8
Inheritance in Python
EXAMPLE
# A Python program to demonstrate inheritance
# Base or Super class. Note object in bracket.
# (Generally, object is made ancestor of all classes)
# In Python 3.x "class Person" is
# equivalent to "class Person(object)"
class Person(object):
# Constructor
def __init__(self, name):
self.name = name
# To get name
def getName(self):
return self.name
# Driver code
emp = Person("Geek1") # An Object of Person
print(emp.getName(), emp.isEmployee())
9
Inheritance in Python
CHAPTER 4
OBJECT CLASS
Like Java Object class, in Python (from version 3.x), object is root of
all classes.
In Python 3.x, “class Test(object)” and “class Test” are same.
In Python 2.x, “class Test(object)” creates a class with object as
parent (called new style class) and “class Test” creates old style class
(without object parent).
10
Inheritance in Python
self.name = name
self.idnumber = idnumber
def display(self):
print(self.name)
print(self.idnumber)
# child class
self.salary = salary
self.post = post
CHAPTER 5
TYPES OF INHERRITANCE IN PYTHON
12
Inheritance in Python
13
Inheritance in Python
14
Inheritance in Python
15