Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

encapsulation in python

# convention: _<name> for protected and __<name> for private
class MyClass: 
    def __init__(self): 
          
        # Protected
        # No access outside of the class or subclasses
        self._this_is_protected = True
        # Private 
        # No access outside of the class
        self.__this_is_private = True

# Note:
# Private and protected members can be accessed outside of the class using python name mangling.
 
PREVIOUS NEXT
Tagged: #encapsulation #python
ADD COMMENT
Topic
Name
3+4 =