- Expert Python Programming(Third Edition)
- Micha? Jaworski Tarek Ziadé
- 282字
- 2021-06-24 14:55:08
Functional-style features of Python
Programming paradigm is a very important concept that allows us to classify different programming languages. Programming paradigm defines a specific way of thinking about language execution models (definition of how work takes place) or about the structure and organization of the code. There are many programming paradigms, but they are usually grouped into two main categories:
- Imperative paradigms, in which the programmer is mostly concerned about the program state and the program itself is a definition of how the computer should manipulate its state to generate the expected result
- Declarative paradigms, in which the programmer is concerned mostly about a formal definition of the problem or properties of the desired result and not defining how this result should be computed
Due to its execution model and omnipresent classes and objects, the paradigms that are the most natural to Python are object-oriented programming and structured programming. These are also the two most common imperative programming paradigms among all modern programming languages. However Python is considered a multi-paradigm language and contains features that are common to both imperative and declarative languages.
One of the great things about programming in Python is that you are never constrained to a single way of thinking about your programs. There are always various ways to solve given problem, and sometimes the best one requires an approach that is slightly different from the one that would be the most obvious. Sometimes, this approach requires the use of declarative programming. Fortunately, Python, with its rich syntax and large standard library, offers features of functional programming, and functional programming is one of the main paradigms of declarative programming.
Let's discuss functional programming in the next section.