Python私有变量
2016-08-25 15:45
483 查看
# 访问限制的保护,代码更加健壮 class Student(object): def __init__(self,name,score): self.__name= name self.__score = score def print_scrore(self): print("%s:%s" % (self.__name,self.__score)) def get_name(self): return self.__name def get_score(self): return self.__score def set_score(self): if 0<=score<=100: self.__score=score else: raise ValueError('bad score') bart = Student('frank',100) print(bart.get_name()) print(bart.get_score())
相关文章推荐
- 有关python私有变量使用的例子
- Python中定义“私有”成员变量和成员函数
- Python 私有变量、私有方法、类变量与实例变量
- Python(私有变量)类中的特殊方法
- python为什么有私有方法和变量
- python技巧(3)——下划线,私有变量
- Python学习之私有函数、私有变量
- Python类中的私有变量
- Python 中特殊变量/方法命名规则说明(特别是私有变量)及使用实例
- Python(私有变量)类中的特殊方法
- Python中定义“私有”成员变量和成员函数
- python的私有变量解析
- python私有方法和变量
- Python中定义“私有”成员变量和成员函数
- Python中定义“私有”成员变量和成员函数
- Python(私有变量)类中的特殊方法
- Python3.2官方文档翻译-多重继承和私有变量
- Python中定义“私有”成员变量和成员函数
- Python(私有变量)类中的特殊方法
- Python(私有变量)类中的特殊方法