我知道,Python中没有'真正的'私有/受保护方法.这种方法并不意味着隐藏任何东西; 我只是想了解Python的作用.
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() # This doesn't work, I get a AttributeError:
# 'Child' object has no attribute '_Child__private'
Run Code Online (Sandbox Code Playgroud)
那么,这种行为是否意味着,"受保护"方法将被继承,但"私有"根本不会被继承?
或者我错过了什么?