docstringを表示するには?

Pythonのdocstringを表示するには、通常は関数やクラス、モジュールなどのオブジェクトに対して __doc__ 属性を使用します。以下は、関数のdocstringを表示する方法です。

python
def my_function(): """ This is a docstring example for my_function. """ pass # 関数のdocstringを表示 print(my_function.__doc__)

このコードでは、my_function 関数のdocstringが print(my_function.__doc__) を使って表示されます。同様に、クラスやモジュールのdocstringも同じ方法で表示できます。

未分類

Posted by ぼっち