You are on page 1of 13

Module 4: Object Oriented

Programming

Dr. Anu Singha


Assistant Professor, Faculty of Engineering and Technology
Sri Ramachandra University, Chennai.

1
Topics to be covered
Class, Attribute and Method
 Inheritance
Polymorphism
Encapsulation
Introduction: Object Oriented Programming
Continue…
Continue…
Continue…
An object has two characteristics:
• Attributes
• Behavior

Let's take an example:


A “parrot” is an object, as it has the following properties:
• name, age, color as attributes
• singing, dancing as behavior
Continue…
In Python, the concept of OOP follows some basic principles:

• Class: A class is a blueprint for the object. We can think of class as a


sketch of a “parrot” with labels.
• Object: An object (instance) is an instantiation of a class. An object is
simply a collection of attributes (variables) and methods (functions)
that act on those data.
• Method: Methods are functions defined inside the body of a class.
They are used to define the behaviors of an object.
Continue…
__init__(): a special method inside of
a class allows to let OS to know that it
is not a normal method, it’s actually a
class method.

Parrot()

name, age

sing()
Self: represents the instance of the
class. By using the “self” keyword we
can access the attributes and methods
of the class in python.
It binds the attributes with the given
arguments.
Tutorials
Continue…
Class and Attributes examples
Continue…
Class Attributes

Instance Attributes
Continue…
Class and Methods examples

You might also like