让python类的方法或特性变成私有

来源:互联网 发布:发型匹配软件 编辑:程序博客网 时间:2024/06/05 05:26

<<Python 基础教程>>

为了让方法或者特性变为私有(从外部无法访问),只要在它们的名字前面加上双下划线:

class Secretive:    def __inaccessible(self):        print 'Best you can't see me...'    def accessible(self):        print 'The secret message is:'        self.__inaccessible()


0 0
原创粉丝点击