Python web crawler notes (iv)

Source: Internet
Author: User
Tags python web crawler

First, high-order function algorithm in Python

1, the sorted () function of the sort sorted () function is a high-order function, you can also accept a key function to implement a custom function ordering, the function specified by key function on each sequence element, and according to the key function returned by the order of the results. By default, the sorting of characters is based on the size of ASCII, because ' Z ' < ' a ', so the uppercase letters are in front of the lower case.

2, the higher-order function can accept the function as a parameter, you can also return the function as a result value, using the Lazy_sum function to define the function sum, the inner function sum can refer to the external function lazy_sum parameters and local variables, when lazy_sum return function sum, The parameters of the variables are stored in the Undo function, which is called the closure () structure, but note that when the Lazy_sum function is called every time a new function is returned, even if the same parameters are passed in:

3, anonymous function, the keyword lambda represents an anonymous function, the x before the colon represents a function parameter, there is a restriction that only one expression, different write return value is the result of the expression, the benefit of anonymous function is not to worry about the function name conflict, anonymous function is a function object, You can assign an anonymous function to a variable, and then use the variable to invoke the function.

4, adorners, because the function is also an object, and the function object can be assigned to a variable, so, through the variable can also call the function,

Python web crawler notes (iv)

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.