|  | 
 
 发表于 2023-2-6 16:54:10
|
显示全部楼层 
| The code you posted will result in an AttributeError, because the __doc__ property of the D class is being redefined as a class method decorated with the property decorator. 
 By using the property decorator, you are indicating that the __doc__ method should behave as a read-only property. However, the __doc__ attribute is already a built-in property of Python classes that provides the docstring for the class.
 
 If you want to define a custom property for the D class, you should give it a different name, such as doc, and use the property decorator to define it:
 复制代码class D:
    @property
    def doc(self):
        return f"I love FishC,..from class{self.__class__.__name__}"
d = D()
print(d.doc)
 | 
 |