创新互联Python教程:python访问限制的实现
说明

1、若要使内部属性不被外部访问,可在属性名称前加两条下划线__。
2、在Python中,如果实例的变量名以__开头,则变成私有变量(private),只有内部可以访问,外部不能访问。
实例
class Student(object):
def __init__(self, name, score):
self.__name = name
self.__score = score
def print_score(self):
print('%s: %s' % (self.__name, self.__score))以上就是python访问限制的实现,希望对大家有所帮助。更多Python学习指路:创新互联python教程
本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。
新闻标题:创新互联Python教程:python访问限制的实现
分享URL:http://www.jxjierui.cn/article/dpephci.html


咨询
建站咨询
