是什么?
class的文档字符串,其实质就是帮助文档。python的类,内置了__doc__方法,对其进行调用。
我们经常会看到这样的代码:(三个单引号的注释就是class的文档字符串):
如何调用:
class Dog:
'''类的文档字符串'''
def __init__(self, color, kind):
'''__init__方法的文档字符串:初始化Dog的属性'''
self.color = color
self.kind = kind
def __del__(self):
'''__del__方法的文档字符串:自动调用的__del__方法释放占用资源'''
pass
#__doc__调用文档字符串
print(Dog.__doc__)
print(Dog.__init__.__doc__)
print(Dog.__del__.__doc__)