python __doc__方法

__doc__方法是python的内置方法之一,该方法通常会输出指定对象中的注释部分。
NB(注意): # 后面的部分表示输出结果
代码如下:

class Debug:
    """
    This is a class for debugging
    """
    def __init__(self):
    	"""
    	This funtion only has one property
		"""
        self.x = 5
        
        
# debug
main = Debug()
print(main.__doc__)  			# This is a class for debugging  
print(main.__init__.__doc__) 	# This funtion only has one property

我们可以看到,输出结果为注释中的内容。其中print(main.__doc__)输出的时Debug类中注释的内容,print(main.__init__.__doc__)输出的是__init__(self)函数中注释的内容。

猜你喜欢

转载自blog.csdn.net/u011699626/article/details/107981264