Functions

Ha Khanh Nguyen (hknguyen)


1. What is a Function?

1.1 Defining a function vs. a function call?


2. Function Properties

2.1 Namespaces, scope, and local functions

2.2 Returning multiple values

2.3 Anonymous (lambda) functions


3. Recursion

(modified from Wikipedia)

Exercise

Write a function named fib() that takes $n$ as an input argument, computes the $n$-th number in the Fibonacci sequence, and return it as the function output.


This lecture note is modified from Chapter 3 of Wes McKinney's Python for Data Analysis 2nd Ed.