Protected& private methods in python

Hello all,
During my python training, I came across OOPS .concepts.This code shows an attribute error while I’m trying to run it

class Parent(object):
    def _protected(self):
        pass

    def __private(self):
        pass

class Child(Parent):
    def foo(self):
        self._protected()   # This works

    def bar(self):
        self.__private()

The protected method works and the private method doesn’t work does it mean protected works while inheritance and private don’t?

That’s what private means. Non-inheritable.

1 Like