I have a function with parameters set to default values. I'm using a NumPy-style docstring, but I've seen the default values written elsewhere. What is the commonly accepted placement for writing "default" in the 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?
'''
Python has a different way of representing syntax and default values for function arguments. Default values indicate that the function argument will take that value if no argument value is passed during the function call. The default value is assigned by using the assignment(=) operator of the form keywordname=value.
If you read further in the document you linked it looks like there's no one standard style:
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`.
I would recommending picking a style for your own project and sticking to it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With