python文档字符串
作者:
ITgecko | 来源:发表于
2018-12-26 15:22 被阅读0次文档字符串docstrings
- 它本身就是一种注释,不过是通过双引号""包裹起来,通过三个双引号包裹,可以写多行。它提供了一种很方便的注释方式,来协助关联文档。包、类、函数、方法都可以用使用文档字符串。
- 可以通过访问
__doc__
属性,查看该对象的文档字符串,或者调用help()函数来查看。上述两种方法,只会显示文档字符串,不会显示普通注释。
class Student():
"一行注释用一对双引号包裹"
# 这是一些注释,help()查看时不会显示出来
def __init__(self, name, score):
self.__name = name
self.name = name
self.__score = score
def print_score(self):
"""
这里是文档字符串,应该是用于介绍函数的描述文字。
help()方法查看时,docstring会显示出来
"""
print('%s: %s' % (self.__name, self.__score))
# token = Student('token', 100)
# token.print_score()
print(help(Student))
print(Student.__doc__)
本文标题:python文档字符串
本文链接:https://www.haomeiwen.com/subject/tassnxtx.html
网友评论