Chapter 4. More Control Flow Tools 28 (continued from previous page) The above example uses a lambda expression to return a function. Another use is to pass a small function as an argument: Here are some conventions about the content and formatting of documentation strings. The first line should always be a short, concise summary of the object’s purpose. For brevity, it should not explicitly state the object’s name or type, since these are available by other means (except if the name happens to be a verb describing a function’s operation). This line should begin with a capital letter and end with a period. If there are more lines in the documentation string, the second line should be blank, visually separating the summary from the rest of the description. The following lines should be one or more paragraphs describing the object’s calling conventions, its side effects, etc. The Python parser does not strip indentation from multi-line string literals in Python, so tools that process documen- tation have to strip indentation if desired. This is done using the following convention. The first non-blank line after the first line of the string determines the amount of indentation for the entire documentation string. (We can’t use the first line since it is generally adjacent to the string’s opening quotes so its indentation is not apparent in the string literal.) Whitespace “equivalent” to this indentation is then stripped from the start of all lines of the string. Lines that are indented less should not occur, but if they occur all their leading whitespace should be stripped. Equivalence of whitespace should be tested after expansion of tabs (to 8 spaces, normally). Here is an example of a multi-line docstring: Function annotations are completely optional metadata information about the types used by user-defined functions (see PEP 3107 and PEP 484 for more information). Annotations are stored in the$_{__annotations__}$ attribute of the function as a dictionary and have no effect on any other part of the function. Parameter annotations are defined by a colon after the parameter name, followed by an expression evaluating to the value of the annotation. Return annotations are defined by a literal$_{->}$ , followed by an expression, between the parameter list and the colon denoting the end of the$_{def}$ statement. The following example has a required argument, an optional argument, and the return value annotated: 4.7.8 Function Annotations 4.7.7 Documentation Strings Python Tutorial, Release 3.9.5 >>> pairs =[(1,'one'), ( 2,'two'), ( 3,'three '), ( 4,'four')] >>> pairs.sort(key= lambda pair: pair[1]) >>> pairs [(4, 'four'), (1, 'one'), (3, 'three'), (2, 'two')] 42 >>> f(1) 43 >>>def my_function (): ... """Do nothing, but document it. ... ... No, really, it doesn't do anything. ... """ ... pass ... >>> print(my_function .__doc__ ) Do nothing, but document it. No, really, it doesn't do anything.