程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Fundamentals of Python - functional programming

編輯:Python

Preface : This article is abstract , First, sort it out and record it , Work slowly to understand .


1、 Functional programming definition

In short ," Functional programming " It's a kind of " Programming paradigm "(programming paradigm), The methodology of how to write a program .
Common programming paradigms are : Process oriented programming , object-oriented programming , Functional programming .

Python It's a multi paradigm programming language , This includes object-oriented programming , Functional programming .

2、 Functional programming features

  • The function is " First class citizens "
    • Functions can be the same as variables , It can be assigned to other variables , It can also be used as a parameter , Pass in a function , Or as the return value of another function .
  • Just use expressions , No statement :
    • An expression is a simple operation , There is always a return value .
    • A statement is to perform an operation , no return value .
    • in other words , Every step in functional programming is a simple operation , And they all have return values .
  • No side effect
    • It will not produce results other than operations .
    • The same input always gets the same data .
  • Immutability
    • Do not modify variables , Returns a new value .
  • Reference transparent
    • The operation of the function does not depend on external variables , It only depends on the input parameters .

3、 The application of functional programming

Higher order function

Partial function

Closure

recursive

The inertia calculation

currying

4、 The advantages of functional programming

The code is concise , Fast development

Close to natural language , Easy to understand

Easier code management

Easy to " Concurrent programming "

Hot code upgrades

5、 The disadvantages of functional programming

The runtime is heavily consumed in CPU And storage resources , Poor performance


reference:

Functional programming _ Baidu Encyclopedia

Programming paradigm — The idea behind the programming language - zhoulujun - Blog Garden


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved