0% found this document useful (0 votes)
131 views

Day 5 Assignment Python Oops Concepts

Python supports object-oriented programming with classes, objects, methods, inheritance, polymorphism, encapsulation and abstraction. Major OOP concepts include: - Classes define collections of objects and their attributes/methods. - Objects are instances of classes that represent real-world entities with states and behaviors. - Methods are functions defined inside classes that act on object attributes. - Inheritance allows child classes to inherit attributes and behaviors from parent classes. - Polymorphism means the same method can act differently depending on the object. - Encapsulation restricts access to certain object attributes and methods for protection.

Uploaded by

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

Day 5 Assignment Python Oops Concepts

Python supports object-oriented programming with classes, objects, methods, inheritance, polymorphism, encapsulation and abstraction. Major OOP concepts include: - Classes define collections of objects and their attributes/methods. - Objects are instances of classes that represent real-world entities with states and behaviors. - Methods are functions defined inside classes that act on object attributes. - Inheritance allows child classes to inherit attributes and behaviors from parent classes. - Polymorphism means the same method can act differently depending on the object. - Encapsulation restricts access to certain object attributes and methods for protection.

Uploaded by

latha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Day 5 Assignment

Python OOPs Concepts


Like other general-purpose programming languages, Python is also an
object-oriented language since its beginning. It allows us to develop
applications using an Object-Oriented approach. In Python, we can
easily create and use classes and objects.
An object-oriented paradigm is to design the program using classes and
objects. The object is related to real-word entities such as book, house,
pencil, etc. The oops concept focuses on writing the reusable code. It is
a widespread technique to solve the problem by creating objects.

Major principles of object-oriented programming system are given


below.
 Class
 Object
 Method
 Inheritance
 Polymorphism
 Data Abstraction
 Encapsulation

Class
The class can be defined as a collection of objects. It is a logical entity
that has some specific attributes and methods. For example: if you have
an employee class, then it should contain an attribute and method, i.e.
an email id, name, age, salary, etc.

Syntax
class ClassName:
<statement-1>
.
<statement-N>
Object
The object is an entity that has state and behavior. It may be any real-
world object like the mouse, keyboard, chair, table, pen, etc.
Everything in Python is an object, and almost everything has attributes
and methods. All functions have a built-in attribute __doc__, which
returns the docstring defined in the function source code.
When we define a class, it needs to create an object to allocate the
memory. Consider the following example.
Example:
class car:
def __init__(self,modelname, year):
self.modelname = modelname
self.year = year
def display(self):
print(self.modelname,self.year)

c1 = car("Toyota", 2016)
c1.display()
Output:
Toyota 2016

Method
The method is a function that is associated with an object. In Python, a
method is not unique to class instances. Any object type can have
methods.

Inheritance
Inheritance is the most important aspect of object-oriented
programming, which simulates the real-world concept of inheritance. It
specifies that the child object acquires all the properties and behaviors
of the parent object.
By using inheritance, we can create a class which uses all the properties
and behavior of another class. The new class is known as a derived class
or child class, and the one whose properties are acquired is known as a
base class or parent class.
It provides the re-usability of the code.

Polymorphism
Polymorphism contains two words "poly" and "morphs". Poly means
many, and morph means shape. By polymorphism, we understand that
one task can be performed in different ways. For example - you have a
class animal, and all animals speak. But they speak differently. Here, the
"speak" behavior is polymorphic in a sense and depends on the animal.
So, the abstract "animal" concept does not actually "speak", but
specific animals (like dogs and cats) have a concrete implementation of
the action "speak".

Encapsulation
Encapsulation is also an essential aspect of object-oriented
programming. It is used to restrict access to methods and variables. In
encapsulation, code and data are wrapped together within a single unit
from being modified by accident.

You might also like