2. WHAT IS PYTHON?
• Python is an interpreted, object-oriented, high-level programming language with dynamic
semantics.
• Its high-level built in data structures, combined with dynamic typing and dynamic binding,
make it very attractive for Rapid Application Development, as well as for use as a scripting
or glue language to connect existing components together.
• Python's simple, easy to learn syntax emphasizes readability and therefore reduces the cost
of program maintenance.
• Python supports modules and packages, which encourages program modularity and code
reuse.
3. COMPOSITION:
we will refine the class person , that comprised the instance attribute name , DOB
and address in addition to the class attribute person count. while creating objects such as ‘24-
10-1990’ as value of the date of birth(DOB). We also defined MyDate class comprising three
components day, month and year . To use this representation of the date in the class Person , we
only need to import the Mydate class in the script and there is no change in the description of
class person.
The use of MyDate class to create instance of person class:
>>dob=MyDate(24,10,1900)
>>p1=person(‘Rajat,Mittal’,dob,’B-23,Malviya nagar , delhi’)
>>print(p1)
Name: Rajat Mittal
DOB :24-10-1990
Address:b-23,Malviya Nagar, Delhi
4. That data attribute dob of object p1 is type MyDate .here we have used an object
of another class Mydate as an attribute of the class person. The process of using
objects of the classes as attribute values is called object composition. It is
important to observe that we have already using this concept subconsciously.
While creating object of class person earlier , we used object of system –define
class str as value of attributes name, DOB, and address . We could have, equally
well, used the object MyDate (24,10,1990) directly as an argument , while invoking
the constructor, instead of first creating it as dob ,as shown below
>>p1=person(‘Rajat Mittal’, MyDate(24,10,1990),b-23,Malviya Nagar ,Delhi’)
5. INHERITANCE:
Inheritance is an important feature of object oriented programming that
imparts ability to a class to inherit properties and behavior of another class. The
class object includes a rich set of special type of function.
Person
is a
Employee
Parent and child class
6. SINGLE INHERITANCE:
when inheritance involves a derived class that derives
its properties from a single base class is called single inheritance. As
another example think of a manager I a factory . The manager would have
all the attribute of an employee and may have some new attributes like
managerial pay.
Person
is an
Manager
Employee and manager class
7. HIERARCHICAL INHERITANCE:
A derived class is like any other class and may serve as
base class for another class derived from it and so on. Each derived
class may define its new attributes. Thus inheritance allows us to
create a class hierarchy also called type hierarchy.
Vehicle
is an is an
passenger Commercial
vehicle vehicle
is a is a is a
car Auto Bus
8. MULTIPLE INHERITANCE:
In the case of multiple inheritance , a subclass derives its attributes from two or
more classes . We make use of multiple inheritance to schedule appointments by
creating a class Appointment .since an appointment will comprise date and time ,
we may inherit the classes MyDate and MyTime in the class appoinment.
MyDate MyTime
Appoinment
Classes Clerk and Manager
We have already developed the class MyDate. We give details of the class
MyTime having data attributes hours, minutes and seconds .
9. ABSTRACT METHODS:
An abstract method in a base class identifies the functionality
that should be implemented by all its subclasses .However,since
the implementation of an abstract method would differ from one
subclass to another , often the method body comprises just a pass
statement .Every subclass of the base class will override this
method with its implementation. A
Class containning abstract methods is called abstract class.