python文档字符串

读书不觉已春深,一寸光阴一寸金。 —— 王贞白《白鹿洞二首·其一》

Python中有个docstring,它可以打印注释。

1
2
3
4
5
A docstring is a string literal that occurs as the first statement in 
a module, function, class, or method definition. Such a docstring
becomes the __doc__ special attribute of that object.

--- PEP

使用

1
2
3
4
5
6
7
8
def ():
'''
打印hello字符串
'''
print("hello")

print(Hey.__doc__)
Hey() # hello