Testing your code
Test-Driven Development
Write the test of a function before you write the function’s body.
- A test will clarify the arguments, return, and behavior of a function.
- Tests can help identify tricky edge cases
Develop incrementally and test each piece before moving on.- You can’t depend on code that hasn’t been tested.
- Run your old tests again after you make new changes.
Comments and Docstrings
Comments: #
Docstring: """ ... """
occurs as the first statement in a module, function, class, or method definition.
Difference between comments and docstrings
These descriptions are what is returned by Python when you type
help(object)
Allows you to write doctests
Loops
Loops are used to access and modify information stored in lists(any iterable storage) and are used to repeat computations many times.
Two types of loops:
For loop: Usually is used when the number of reps is known.
While: Uses logical conditions, do not know the number of iterations.
Break Statement
Terminates the current loop and resumes execution at the next statement
The most common use for break is when some external condition is triggered requiring a hasty exit from a loop.
The break statement can be used in both while and for loops.