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

PPS U5 Module3 (C)

Polymorphism allows defining functions with same name but different signatures that can work with different types. It is demonstrated through built-in print and len functions as well as user-defined add function. Encapsulation wraps data and methods together within a class, restricting access and preventing accidental modification of data. Abstraction hides internal implementation details and only exposes relevant functionality through basic use, like a smartphone interface. Data abstraction in Python allows hiding attributes from outside a class by prefixing them with double underscore.

Uploaded by

Sanny Wagh
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)
8 views

PPS U5 Module3 (C)

Polymorphism allows defining functions with same name but different signatures that can work with different types. It is demonstrated through built-in print and len functions as well as user-defined add function. Encapsulation wraps data and methods together within a class, restricting access and preventing accidental modification of data. Abstraction hides internal implementation details and only exposes relevant functionality through basic use, like a smartphone interface. Data abstraction in Python allows hiding attributes from outside a class by prefixing them with double underscore.

Uploaded by

Sanny Wagh
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
You are on page 1/ 6

Polymorphism : The word polymorphism means having many forms.

In programming, polymorphism means same function name (but different signatures)


being uses for different types.

# Example of inbuilt polymorphic functions :

print(len("comp")) Output:

print(len([10, 20, 30])) 4

3
Example of user defined polymorphic functions :

def add(x, y, z):

return x+y+z
Output :

print(add(2,3,4)) 9

print(add(1.1, 2.2, 3.3)) 6.6


Encapsulation: It is one of the fundamental concepts in object-oriented programming (OOP).
It describes the idea of wrapping data and the methods that work on data within one unit.

A class is an example of encapsulation as it encapsulates all the data that is member functions,
variables, etc.

This puts restrictions on accessing variables and methods directly and can prevent the
accidental modification of data. To prevent accidental change, an object’s variable can only be
changed by an object’s method. Those types of variables are known as private variable.
Abstraction in Python:
Abstraction is used to hide the internal functionality of the function from the users. The
users only interact with the basic implementation of the function, but inner working is
hidden. User is familiar with that "what function does" but they don't know "how it
does."
In simple words, we all use the smartphone and very much familiar with its functions such
as camera, voice-recorder, call-dialing, etc., but we don't know how these operations are
happening in the background.
Let's take another example - When we use the TV remote to increase the volume. We
don't know how pressing a key increases the volume of the TV. We only know to press the
"+" button to increase the volume.That is exactly the abstraction that works in the
object-oriented concept.
Why Abstraction is Important?

In Python, an abstraction is used to hide the irrelevant data in order to reduce the
complexity. It also enhances the application efficiency.
Data abstraction in python
Abstraction is an important aspect of object-oriented programming. In python, we can
also perform data hiding by adding the double underscore (___) as a prefix to the
attribute which is to be hidden. After this, the attribute will not be visible outside of the
class through the object.
Thanks

You might also like