Part 1 · Section 06

First-Class Functions

In Python a function is not a special, frozen piece of syntax: it is an object, just like an integer or a list. It has a type and attributes, you can bind it to any name, put it in a container, pass it to another function and return it from one. Languages that allow this are said to have first-class functions, and much of idiomatic Python is built on top of that idea.

This section explores what you can do once you treat functions as values. You’ll attach documentation and metadata to them, write tiny anonymous functions with lambda, hand functions to sorted, map, filter and reduce, examine a function’s parameters with the inspect module, and build new functions out of existing ones with functools.partial and the operator module.

In this section you’ll learn:

Lectures

  1. 01Docstrings and Annotations✓
  2. 02Lambda Expressions✓
  3. 03Lambdas and Sorting✓
  4. 04Challenge - Randomizing using Sorted✓
  5. 05Function Introspection✓
  6. 06Callables✓
  7. 07Map, Filter, Zip and List Comprehensions✓
  8. 08Reducing Functions✓
  9. 09Partial Functions✓
  10. 10The operator Module✓

Practice: quiz & exercises

12 quiz questions · 4 coding exercises

Go to practice →