Functions as First-Class Objects
Understand closures and passing functions as arguments.
Introduction
In Python, functions are first-class objects: they can be passed as arguments, returned, and stored in data structures.
Functions are Objects
def double(x): return x*2 creates a function object. double is just a name. You can assign it: fn = double; fn(5) works.
def double(x): return x * 2
fn = double
print(fn(5))
print(type(fn))All lessons in this course
- Functions as First-Class Objects
- Writing Custom Decorators
- The @property Decorator
- @classmethod and @staticmethod