PPS U5 Module3 (C)
PPS U5 Module3 (C)
print(len("comp")) Output:
3
Example of user defined polymorphic functions :
return x+y+z
Output :
print(add(2,3,4)) 9
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