#python #sicp
Doctests. Python provides a convenient method for placing simple tests
directly in the docstring of a function. The first line of a docstring should
contain a one-line description of the function, followed by a blank line. A
detailed description of arguments and behavior may follow. In addition, the
docstring may include a sample interactive session that calls the function:
If you want to change selection, open document below and click on "Move attachment"
1.5 Control assert fib(50) == 7778742049, 'Error at the 50th Fibonacci number'
When writing Python in files, rather than directly into the interpreter, tests
are typically written in the same file or a neighboring file with the suffix
_test.py .
<span>Doctests. Python provides a convenient method for placing simple tests
directly in the docstring of a function. The first line of a docstring should
contain a one-line description of the function, followed by a blank line. A
detailed description of arguments and behavior may follow. In addition, the
docstring may include a sample interactive session that calls the function:
>>> def sum_naturals(n):
"""Return the sum of the first n natural numbers.
>>> sum_naturals(10)
55
>>> sum_n Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details