0Pricing
Python Academy · Lesson

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

  1. Functions as First-Class Objects
  2. Writing Custom Decorators
  3. The @property Decorator
  4. @classmethod and @staticmethod
← Back to Python Academy