python中 @property
考察 Student 类:
1 class Student(object): 2 def __init__(self, name, score): 3 self.name = name 4 self.score = score
当我们想要修改一个 Student 的 scroe 属性时,可以这么写:
1 s = Student('Bob', 59) 2 s.score = 60
考察 Student 类:
1 class Student(object): 2 def __init__(self, name, score): 3 self.name = name 4 self.score = score
当我们想要修改一个 Student 的 scroe 属性时,可以这么写:
1 s = Student('Bob', 59) 2 s.score = 60