{
    "content": "<h1>Encapsulation in <a href=\"..\/Python\/\">Python<\/a><\/h1><p><a href=\"..\/Encapsulation\/\">Encapsulation<\/a> is a fundamental pillar of <a href=\"..\/Object-Oriented Programming\/\">Object-Oriented Programming<\/a> (OOP). It refers to the bundling of data and the methods that operate on that data into a single unit, known as a <a href=\"..\/Class\/\">Class<\/a>. In <a href=\"..\/Python\/\">Python<\/a>, this mechanism is primarily used to restrict direct access to certain components of an object, which is a concept known as <a href=\"..\/Data Hiding\/\">Data Hiding<\/a>. This ensures that the internal state of an object is protected from unintended interference and misuse.<\/p><h2>Access Modifiers and Conventions<\/h2><p>Unlike languages such as Java or C++, <a href=\"..\/Python\/\">Python<\/a> does not enforce strict private or protected access modifiers. Instead, it relies on naming conventions to signal the intended visibility of a member:<\/p><ul><li><strong>Public Members:<\/strong> These are accessible from anywhere outside the class. Any member without a leading underscore is public.<\/li><li><strong>Protected Members:<\/strong> By convention, a single leading underscore (e.g., <code>_variable<\/code>) indicates that a member is intended for internal use within the class and its subclasses.<\/li><li><strong>Private Members:<\/strong> A double leading underscore (e.g., <code>__variable<\/code>) invokes <a href=\"..\/Name Mangling\/\">Name Mangling<\/a>, where the interpreter changes the name of the variable to include the class name, making it harder to access from outside the scope of the <a href=\"..\/Class\/\">Class<\/a>.<\/li><\/ul><h2>The Property Decorator<\/h2><p>To provide a controlled interface for accessing and modifying private data, <a href=\"..\/Python\/\">Python<\/a> provides the <code>@property<\/code> decorator. This allows developers to define <a href=\"..\/Getters and Setters\/\">Getters and Setters<\/a>, enabling validation logic or computations to occur when a value is retrieved or assigned. Detailed technical specifications can be found in the official <a href=\"https:\/\/docs.python.org\/3\/tutorial\/classes.html#private-variables\">Python Documentation<\/a> and further practical examples are available at <a href=\"https:\/\/realpython.com\/python-encapsulation\/\">Real Python<\/a>.<\/p><ul><li><a href=\"..\/Inheritance\/\">Inheritance<\/a><\/li><li><a href=\"..\/Polymorphism\/\">Polymorphism<\/a><\/li><li><a href=\"..\/Abstraction\/\">Abstraction<\/a><\/li><li><a href=\"..\/Method Overriding\/\">Method Overriding<\/a><\/li><\/ul>",
    "tags": [
        "encapsulation",
        "python",
        "oop",
        "classes",
        "data-hiding",
        "name-mangling",
        "programming",
        "software-development",
        "access-modifiers",
        "abstraction"
    ]
}