Python Programming Unit – II (Part III) (Lecture 12) Fruitful functions Return values Incremental development Nested functions
Fruitful functions Lecture 12 Lecture 13 Return values Incremental development Nested functions Boolean functions More recursion Checking types
Fruitful functions Lecture 12 Return values Incremental development Nested functions
• 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
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
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
Fruitful functions Lecture 12 Return values Incremental development Nested functions
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.
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:
Fruitful functions Lecture 12 Return values Incremental development Nested functions
Nested functions • We can call one function from within another. This ability is called composition.
Fruitful functions Lecture 12 Return values Incremental development Nested functions
Python Programming Unit – II (Part III) (Lecture 13) Fruitful functions Boolean functions More recursion Checking types
Fruitful functions Lecture 12 Lecture 13 Return values Incremental development Nested functions Boolean functions More recursion Checking types
Fruitful functions Lecture 13 Boolean functions More recursion Checking types
Boolean functions • Functions can return Booleans. • For hiding complicated tests inside functions.
Fruitful functions Lecture 13 Boolean functions More recursion Checking types
More recursion
More recursion
Fruitful functions Lecture 13 Boolean functions More recursion Checking types
Checking types
Checking types • We can use the built-in function isinstance to verify the type of the argument.
Fruitful functions Lecture 13 Boolean functions More recursion Checking types

Python Programming | JNTUA | UNIT 2 | Fruitful Functions |