Chapter 3. Functions - Python Numerical Methods
Chapter 3. Functions - Python Numerical Methods
This notebook contains an excerpt from the Python Programming and Numerical Methods - A Guide for Contents
Engineers and Scientists, the content is also available at Berkeley Python Numerical Methods. CHAPTER OUTLINE Print to PDF
Motivation
The copyright of the book belongs to Elsevier. We also have this interactive book online for a better
learning experience. The code is released under the MIT license. If you find this content useful, please
consider supporting the work on Elsevier or Amazon!
< Chapter 2 Summary and Problems | Contents | 3.1 Function Basics >
Chapter 3. Functions
CHAPTER OUTLINE
3.1 Function Basics
3.2 Local Variables and Global Variables
3.3 Nested Functions
3.4 Lambda Functions
3.5 Functions as Arguments to Functions
3.6 Summary and Problems
Motivation
Programming often requires repeating a set of tasks over and over again. For example, the math.sin function in
Python is a set of tasks (i.e., mathematical operations) that computes an approximation for sin (x). Rather than having
to retype or copy these instructions every time you want to use the sin function, it is useful to store this sequence of
instruction as a function that you can call over and over again.
Writing your own functions is the focus of this chapter, and it is the single most powerful use of computer
programming. By the end of this chapter, you should be able to declare, write, store, and call your own functions.
© Copyright 2020.
https://pythonnumericalmethods.berkeley.edu/notebooks/chapter03.00-Functions.html 1/1