s
Size: a a a
s
s
s
А
__init__
как дандер рассказываешь?s
s
s
s
__name__ __dict__
и тдs
__init__
и сразу подразумеваю что это метод классаs
__init__
как дандер рассказываешь?s
s
s
s
# Creating a class
class A:
# Declaring public method
def fun(self):
print("Public method of class A")
# Declaring protected method
def _fun(self):
print("Protected method of class A")
self.__fun()
# Declaring private method
def __fun(self):
print("Private method of class A")
class B(A):
# Declaring public method
def fun(self):
print("Public method of class B")
self._fun()
# Declaring private method
def __fun(self):
print("Private method of class B")
obj = B()
obj.fun()
>>Public method of class B
>>Protected method of class A
>>Private method of class A
s
obj._fun()
>>Protected method of class A
>>Private method of class A
s
obj.__fun()
>>AttributeError: 'B' object has no attribute '__fun'
s
obj._A__fun()
>>Private method of class A
obj._B__fun()
>>Private method of class B
s
print(B.__dict__)то есть при создании словаря объекта B и A - имя метода которое начинается с двойного подчеркивания становится
>>{'__module__': '__main__', 'fun': <function B.fun at 0x0000017768917620>, '_B__fun': <function B.__fun at 0x0000017768B17268>, '__doc__': None}
_classname__methodname
s
obj.__fun = obj.__getattribute__('_A__fun')
obj.__fun()
>>Private method of class A