Functional Programming

Learn about the concept of functional programming in Python.

Definition

Definitions of functional programming differ, but in general functional programming means

  • Functions are objects, and they can be treated like any other value.
  • Variables are single assignment. Once given a value, they are never changed.
  • All functions are pure. The value returned by a function depends only on the arguments given to it, and if called again with the same arguments, it will produce the same value. This excludes any use of global variables or other external factors, such as the system clock.

Functional programming is widely regarded as an ivory-tower technique, not suitable for day-to-day programming. This is not the place to challenge that viewpoint, other than to note that all modern programming languages support functional programming to a greater or lesser extent.

The functions are objects viewpoint

In this lesson, we consider only the first point above: that functions are objects. We will consider only a single example of such a use.

In the following example, the biggest function will find the largest value in a list of values:

Get hands-on with 1200+ tech skills courses.