我有一个参数设置为默认值的函数。我正在使用 NumPy-style docstring,但我在其他地方看到了默认值。在文档字符串中编写“默认”的普遍接受位置是什么?
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`.
我建议为您自己的项目选择一种风格并坚持使用。
关于python - 在 python 文档字符串中编写默认值的标准方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34882861/