Skip to content

Latest commit

 

History

History
22 lines (15 loc) · 624 Bytes

File metadata and controls

22 lines (15 loc) · 624 Bytes

Functions as Objects

In Python, functions are first-class objects — they can be used anywhere any other object can. See First-class function — Wikipedia.

What this means

A function can be:

  • Assigned to a variable
  • Stored in a list or dictionary
  • Used as an attribute of an object
  • Passed as an argument to another function
  • Returned as the result of a function call

Higher-order functions

A function that takes or returns another function. apply(f, x, y) and compose(f, g) are examples here.

Run

python functions_as_objects.py