您的位置:首页 > 编程语言 > Python开发

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

2016-01-07 17:04 417 查看
<<Python 基础教程>>

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

class Secretive:
def __inaccessible(self):
print 'Best you can't see me...'
def accessible(self):
print 'The secret message is:'
self.__inaccessible()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: