Home >Backend Development >Python Tutorial >What is python functional programming?
In the following article, we will learn about what functional programming in python is. Understand what functional programming in python means and where python programming functions can be applied.
Functional programming
Function is a kind of encapsulation supported by Python's built-in support. We split large sections of code into functions and call them layer by layer. , complex tasks can be decomposed into simple tasks. This decomposition can be called process-oriented programming. Functions are the basic unit of process-oriented programming.
And Functional Programming (please note the additional word "formula") - Functional Programming, although it can also be attributed to process-oriented programming, its ideas are closer to mathematical calculations .
We must first understand the concepts of computer and computing.
At the computer level, the CPU executes instruction codes for addition, subtraction, multiplication and division, as well as various conditional judgments and jump instructions. Therefore, assembly language is the language closest to the computer.
Computing refers to calculations in the mathematical sense. The more abstract the calculation, the farther away it is from the computer hardware.
corresponds to programming languages, that is, the lower-level language is closer to the computer, has a lower level of abstraction, and has higher execution efficiency, such as C language; the higher-level language is closer to computing, has a higher level of abstraction, and has lower execution efficiency. , such as Lisp language.
Characteristics of functional programming:
1. Treat calculations as functions rather than instructions
2. Pure functional programming: no variables required , no side effects, simple testing
3. Support high-order functions, simple code
Functional programming supported by Python:
Not pure functional programming: variables are allowed
Supports higher-order functions: functions can also be passed in as variables
Supports closures: with closures, functions can be returned
Limited support for anonymous functions
Functional programming is a programming paradigm with a high degree of abstraction. Functions written in purely functional programming languages have no variables. Therefore, any function, As long as the input is certain, the output is certain. We call this pure function without side effects. In programming languages that allow the use of variables, since the variable status inside the function is uncertain, the same input may result in different outputs. Therefore, this kind of function has side effects.
One feature of functional programming is that it allows the function itself to be passed into another function as a parameter, and it also allows a function to be returned!
Python provides partial support for functional programming. Since Python allows the use of variables, Python is not a purely functional programming language
The above is the detailed content of What is python functional programming?. For more information, please follow other related articles on the PHP Chinese website!