Python Functional Programming-------python2.7 Tutorial Learn "Liao Xuefeng Edition" (v)

Source: Internet
Author: User
Tags abs

June 13, 2017 19:08:13

Task:

Read Functional programming

Notes:

The Reading: Functional programming
1. Functions are a kind of encapsulation supported by Python, and we can break down complex tasks into simple tasks by splitting large pieces of code into functions and using a layer of function calls, which can be called process-oriented programming. function is the basic unit of process-oriented program design.
Understanding: A function is a basic unit of process-oriented, which reminds me of the words in C.
2. 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!
Understanding: Functional programming is a very high degree of abstraction of the programming paradigm, pure functional programming language is written in a function without variables, so any function, as long as the input is determined, the output is determined, 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.
3.Python provides partial support for functional programming. Because Python allows the use of variables, Python is not a purely functional programming language.
4. The function itself can also be assigned to a variable, that is: A variable can point to a function.
5. If a variable points to a function, the function can be called through a variable.
6. The function name is actually a variable pointing to the function! For the ABS () function, it is perfectly possible to think of ABS as a variable, which points to a function that calculates the absolute value!
7. The function name is also a variable.
8. Since the variable can point to a function, the function's parameters can receive the variable, then one function can receive another function as a parameter, this function is called the higher order function.
9. Writing higher-order functions is to allow the function's parameters to receive other functions.
10. Passing functions as parameters, such functions are called higher-order functions, and functional programming refers to this highly abstract programming paradigm.
The 1.map () function receives two parameters, one is a function, the other is a sequence, and the map functions the incoming function to each element of the sequence sequentially and returns the result as a new list.
2.reduce functions a function in a sequence [X1, x2, x3 ...] , the function must receive two parameters, and reduce will continue to accumulate the result and the next element of the sequence,
The 3.Python built-in filter () function is used for filtering sequences.
4. Like map (), filter () also receives a function and a sequence. When different from map (), filter () applies the incoming function to each element sequentially, and then decides whether to persist or discard the element based on whether the return value is true or false.
The 5.Python built-in sorted () function allows you to sort the list:
The 6.sorted () function is also a higher-order function, and it can also receive a comparison function to implement a custom sort.
Summarize:

is really more and more exciting at the same time, understanding more and more need to look at, refueling.

To see the return function

Python Functional Programming-------python2.7 Tutorial Learn "Liao Xuefeng Edition" (v)

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.