python进阶五(定制类)【5-6 python中@property】

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

猜你喜欢

转载自www.cnblogs.com/ucasljq/p/11626771.html