LoginSignup
0
0

More than 1 year has passed since last update.

[Python]docstringのNumPyスタイルの書き方

Posted at

docstringNumPyスタイルの書き方について簡単にメモしておく。
docstringとは、関数やクラスに対する説明を記載する方法の1つ。docstringを記載することで、ドキュメントをHTML形式で自動生成することもできる。

NumPyスタイル

基本的な書き方

基本的な書き方は、reStructuredTextスタイルGoogleスタイルと同じで、関数やクラス定義の先頭に'''または"""で説明を囲む形で記載する。

def my_function():
    """<関数の説明を記載>"""

スタイルごとの違いとしては、引数や返り値などの書き方が異なっている。

記載サンプル

NumPyスタイルでの引数や返り値などの記載例は以下のようになる。
サンプルで使用していないセッションについては下記ページを参照。
https://numpydoc.readthedocs.io/en/latest/format.html#sections

class Sample():
    """<クラスの概要>

    <クラスの詳細説明>

  Attributes
  ---------
  <属性名> : <型>
      <説明>
    """

    def my_function():
        """<関数の概要>

        <関数の詳細説明>

        Parameters
      ---------
        <変数名> : <型>
            <説明>

        Returns
      ---------
        <戻り値名>: <型> 
            <説明>

        Raises
      ---------
        <例外名>
            <説明>
        """

        <関数の処理内容>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0