Lecture 15
Functions as values & lambda
MCS 260 Fall 2020
Emily Dumas
Reminders
Quiz 5 is due today
Work on Project 2, due Oct 9
Live coding
A unary calculator REPL
Live coding
A unary calculator REPL
Recap
- Functions are values in Python, just like float, int, etc.
- Functions can be assigned to variables, used as parameters, stored in lists, used as keys or values
- Dictionary mapping string to function can be used for handlers
sys.exit()
exits program immediately
lambda vars: retval
defines an anonymous function
- Don't use
lambda
for complicated functions
- Assigning to a return value is a good way to handle functions that need to change vars outside of their scope
Revision history
- 2020-09-26 Initial publication