0Pricing
Python Academy · Lesson

First-Class Functions

Pass and return functions.

Functions are objects

In Python, functions are first-class objects. They can be assigned to variables, stored in data structures, passed as arguments, and returned from other functions — just like numbers or strings.

def greet():
    return 'hi'
print(type(greet))
print(greet())

Assigning functions to variables

A function name is just a reference. Assign it to another name and call through that name — no parentheses when referring to the function itself.

def shout(text):
    return text.upper()
yell = shout
print(yell('hello'))

All lessons in this course

  1. First-Class Functions
  2. Closures and Free Variables
  3. nonlocal and Mutable State
  4. Partial Functions
← Back to Python Academy