python Classes and Objects Encapsulation in hindi
•Classes and Objects
•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.
Example of Class
# A sample method
# Driver code
obj = Test()
•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 doc string defined in the function source code.
•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.
- 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.
•Data abstraction and encapsulation both are often used as synonyms.
•Both are nearly synonym because data abstraction is achieved through encapsulation.
•Abstraction is used to hide internal details and show only functionalities.
•Abstracting something means to give names to things so that the name captures the core of what a function or a whole program does.