20190322——Python面向对象高级编程

使用_slot_ 为了给所有实例都绑定方法,可以给class绑定方法: >>> def set_score(self, score): ... self.score = score ... >>> Student.set_score = set_score 但是,如果我们想要限制实例的属性怎么办?比如,只允许对Student实例添加name和age属性。 为了达到限制的目的,Python允
相关文章
相关标签/搜索