This document discusses Python programming concepts including fruitful functions, return values, incremental development, nested functions, Boolean functions, recursion, and type checking. Fruitful functions allow a function to return a value that can be used. Return values terminate function execution, and code after a return is dead code. Incremental development adds and tests small amounts of code at a time to avoid long debugging sessions. Nested functions allow one function to be called within another through composition. Boolean functions return True or False values. Recursion and type checking with isinstance are also covered.
4. • As soon as a return statement executes, the function terminates
without executing any subsequent statements.
• Code that appears after a return statement is called dead code.
Return values
5. Return values
Function:
Statement 3
Statement 4
Statement 5
Statement 6
….
….
Program:
Statement 1
Statement 2
Call function
Statement 7
Call function
….
….
Executed
Function without return
6. Return values
Function:
Statement 3
Statement 4
return
Statement 5
Statement 6
….
….
Program:
Statement 1
Statement 2
Call function
Statement 7
Call function
….
….
Executed
Function with return
Dead code
8. Incremental development
• Larger functions are difficult to debug.
• To deal with complex programs, use incremental development.
• The goal of incremental development is to avoid long debugging
sessions by adding and testing only a small amount of code at a time.
9. Incremental development
• Suppose you want to find the distance between
two points, given by the coordinates (x1, y1) and
(x2, y2).
• By the Pythagorean theorem, the distance is: