1. 程式人生 > >Python中print(__doc__)作用的教程

Python中print(__doc__)作用的教程

作用

輸出檔案開頭註釋的內容

推廣

1)momodule.py

"""This is the module docstring."""

def f(x):
    """This is the function docstring."""
    return 2 * x

2)執行

>>> import mymodule
>>> mymodule.__doc__
'This is the module docstring.'
>>> mymodule.f.__doc__
'This is the function docstring.'

參考資料