datarekha
Python Easy Asked at GoogleAsked at MetaAsked at Amazon

What does it mean for functions to be first-class objects in Python?

The short answer

First-class functions can be stored in variables, passed as arguments, returned from other functions, and placed in data structures — just like any other object. This is the foundation for higher-order functions, decorators, callbacks, and functional programming patterns in Python.

How to think about it

What this really means

“First-class” just means functions are values — full objects you can pass around like integers or strings. In Python every function is an instance of the function type and carries attributes (__name__, __doc__, __annotations__, __closure__). Understanding this unlocks decorators, callbacks, and functional patterns.

Four things you can do with a first-class function

  1. Store in a variableop = square
  2. Store in a data structure — dispatch tables, pipelines
  3. Pass as an argument — higher-order functions like sorted(key=func)
  4. Return from a function — factory functions, decorators

Practical patterns that rely on first-class functions

  • sorted(items, key=func) — pass a function as the sort criterion.
  • functools.partial — fix some arguments and return a new callable.
  • Dependency injection — pass behaviour rather than inheriting it.
  • Dispatch tables — a dict of callables instead of long if/elif chains.

The key insight

Because functions are objects, all the patterns above require zero special syntax. The language doesn’t need a special “callback keyword” or “strategy object” concept — you just pass a function. That’s the payoff of first-class status.

Learn it properly Functions

Keep practising

All Python questions

Explore further

Skip to content