Functional programming - Functional programming in Python
Keyboard shortcuts
Press ← or → to navigate between chapters
Press S or / to search in the book
Press ? to show this help
Press Esc to hide this help
Functional programming
Functional programming has several key aspects or we might call them “preferences”.
- Immutability: Variables, despite their name, don’t change.
- Separation of data and functions.
- Pure functions: Functions have no side-effects.
- First-class functions: You can assign a function to another name. You can pass function to other functions and return them as well. You can also manipulate functions.
- Higher order functions: A functions that either takes a function as a parameter or returns a function as a parameter.
In Python functional programming just blends in the rest of the code. You already used some functional constructs without probably realizing that they functional.
It also seems that Object Oriented programming and Functional programming are two very different styles. One could say they are ortoghonal to each other, but in Python you can combine them.
Let’s start with some simple things.