python类中的私有方法

>>> class Template():
    def ___haha():
        pass

   
>>> t=Template()
>>> dir(t)
['_Template___haha', '__doc__', '__myodule__']

当方法以__开头后,会认为它是一个私有的方法,外部不能调用,其实是因为python帮我们改名了,如上所式的___haha方法变成了
_+类名+原方法名的形式

原文地址:https://www.cnblogs.com/lexus/p/1683585.html