ChecklistFor every function you are writing, consider the following suggestions to remove as many errors from your work as possible:
What makes a good documentation string?A good documentation string comments on (i) the Parameters given to the function, (ii) the return value of the object and (iii) what the function does to get from the parameters to the return value. Here is a minimalistic example: def average(a, b): """Given Parameters a and b, compute and return the arithmetic mean of a and b.""" return (a + b) * 0.5 Sometimes, it may be appropriate to comment on the type of parameters and return values. As a minimum guidance, the documentation string should explain what the parameters are (and use of the word parameters is encouraged) and what the function returns (and use of the word returns is encouraged). Going beyond this, the documentation string needs to provide a reasonable summary of (i) what the function does and (ii) what restrictions there are on the valibity of results or values of parameters. One needs to use common sense here. You may want to use python's help function or Spyder's object explorer to see examples of documentation strings from in-built Python commands or library functions. For the short practice functions we write in this course, the documentation string may often seen unnecessary, but it is good practice to create at least a short documenation string that explains what the parameters and return values are. See also how to structure docstrings so they look nice in Spyder. Advanced suggestions
|
|