T
一个装饰器,使得类中方法像属性一样被使用。
W
这是原本的类及其属性的访问
class Person():
def __init__(self, firstname:str, lastname:str):
self.first = firstname
self.last = lastname
self.full_name = self.first + ' '+ self.last
def printFullname(self):
return f"Full name is {
self.full_name}."
person = Person('Jack','Swingming')
print(f"{
person.first=}")
print(f"{
person.last=}")
print(f"{
person.full_name=}")
print(f"{
person.printFullname()=}")
person.first='Jack'
person.last='Swingming'
person.full_name='Jack Swingming'
person.printFullname()='Full name is Jack Swingming.'
但是如果我修改了self.first,我希望full_name 一起修改,该如何做呢?
这里就用函数可以实现
class Person():
def __init__(self, firstname:str, lastname

最低0.47元/天 解锁文章
497

被折叠的 条评论
为什么被折叠?



