Python-Functional programming

Source: Internet
Author: User
Tags abs

Functional programming is a very high degree of abstraction of the programming paradigm, the purely functional programming language functions are not variable, so any function, as long as the input is determined, the output is OK, this pure function we call no side effects. In the case of programming languages that allow the use of variables, because of the variable state inside the function, the same input may get different output, so this function has side effects.

One of the features of functional programming is that it allows the function itself to be passed as a parameter to another function, and also allows a function to be returned!

Python provides partial support for functional programming. Because Python allows the use of variables, Python is not a purely functional programming language.

Higher order function: One function can receive another function as a parameter

A variable can point to a function, and the function itself can be assigned to a variable, and the function name is also a variable

Such as:

In []: absout[]: <function abs> in[+]: ABS ( -20) out[]:[+]: x = Absin [+]: X ( -2) out[23]: 2

Incoming function

def sum (x, y):   ....:     return x+yIn [def  de (x, y):   ...      ..: return xy ....: in   [def  Cal (X,y,sum,de): ....   :       return sum (x, y) *de (x, y) ....   : In []: cal (2,5, sum,de) out[28]: 21

Python-Functional programming

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.