Functional Programming in Python
Introduction
Functional Programming is a popular programming paradigm closely linked to computer science’s mathematical foundations. While there is no strict definition of what constitutes a functional language, we consider them to be languages that use functions to transform data.
Python is not a functional programming language but it does incorporate some of its concepts alongside other programming paradigms. With Python, it’s easy to write code in a functional style, which may provide the best solution for the task at hand.
Functional Programming Concepts
Functional languages are declarative languages, they tell the computer what result they want. This is usually contrasted with imperative languages that tell the computer what steps to take to solve a problem. Python is usually coded in an imperative way but can use the declarative style if necessary.
Some of Python’s features were influenced by Haskell, a purely functional programming language. To get a better appreciation of what a functional language is, let’s look at features in Haskell that can be seen as desirable, functional traits:
- Pure Functions – do not have side effects, that is, they do not change the state of the program. Given the same input, a pure