在 python 文档字符串中写入默认值的标准方法是什么?

What is the standard way for writing default values in a python docstring?

我有一个参数设置为默认值的函数。我使用的是 NumPy-style 文档字符串,但我在别处看到了默认值。在文档字符串中写入“默认”的普遍接受位置是什么?

def some_func(a_num=None, a_string=None):
    ''' A function that does something special.

    Parameters
    ==========
    a_num : int, default 100                        # is it written here?
        An important number.
    a_string : str, default 'foo'
        A useful string.  Default is 'foo'.         # or here?    
 
    '''

如果您进一步阅读所链接的文档,您会发现似乎没有一种标准样式:

Optional keyword parameters have default values, which are displayed as part of the function signature. They can also be detailed in the description:

Description of parameter `x` (the default is -1, which implies summation
over all axes).

When a parameter can only assume one of a fixed set of values, those values can be listed in braces, with the default appearing first:

order : {'C', 'F', 'A'}
    Description of `order`.

我建议为您自己的项目选择一种风格并坚持下去。