In Python function programming, we can define an anonymous function, or assign a function to a variable or pass it as a parameter to another function, the Code is as follows:
- >>> F=Lambda(N): n ** 2
- >>>F (6)
- 36
-
- >>> F=Lambda(N): lambda (m): n * m
- >>> G=F(5) # equivalentG=Lambda(M): 5 * m
- >>>G (9) # equivalent to 5*9
- 45
The anonymous function defined by lambda can reference the variables of the peripheral function. In the code above, the anonymous function defined by the second lambda expression references the parameter n of the first anonymous function, because the first anonymous function is the peripheral function of the second anonymous function.
In addition to lambda expressions, python also supports passing functions as parameters to another function, which is somewhat similar to the function pointer in C language. The built-in function filter, map, reduce can accept function parameters.
Filter (function, sequence) traverses every item in the sequence and calls the function with this item as the parameter. If the function returns true, the item is added to the result sequence, this achieves the effect of sequence filtering. The function as a parameter is a filter condition, as shown in the following example:
- >>> def add(x,y):
- return x+y
-
- >>> reduce(add,range(1,10))
- 45
IT usually involves a lot of tasks, but few resources are needed to support these tasks. This has become a public secret. Any IT solution that promises to improve coding efficiency and reduce software costs should be carefully considered. A significant advantage of Python is that it can save a lot of money in the Software creation and maintenance phase of the enterprise, and the software costs in these two stages account for 50% to 95% of the total cost of the entire software lifecycle.
The clear and readable Syntax of Python makes the software code exceptionally easy to understand, and even the strong feeling for programmers who are not initially engaged in and developing the original project. Although some programmers oppose the extensive use of spaces in Python code.
However, almost everyone acknowledges that the readability of Python code is far better than that of C or Java, the latter two adopt special character mark code block structures, loops, functions, and other programming structures to start and end. Those who advocate Python also claim that using these characters may produce significant differences in programming style, making it difficult for those who are responsible for maintaining the code to read the code.
Python's clear syntax makes it a learning curve and programming language. Experienced programmers may even master the basic knowledge of Python within one day, but they will be able to get started after at most one week, programming Language experts will certainly be much faster than their knowledge of C, C ++, Java, and even Perl.
The biggest benefit of Python function programming due to its clear syntax may be that the development time is greatly reduced. A developer engaged in enterprise-level application development told me that the development time of his unit was greatly reduced by the adoption of Python.
- Learn Python source files
- How to define Python Functions
- How to Write Python correctly
- Powerful Python language Introduction
- Big secrets about Python programs
At the same time, it did not bring any negative impact to the software performance, he said: "In our business, developing new products quickly is much more important than developing software products with amazing performance, the development time is much more expensive than the software optimization in hourly calculation ).
It is always difficult to determine the criteria used for development speed. However, it is generally believed that the speed of developing Python applications is about 10 times faster than that of developing similar applications using Java. It will save more time than C/C ++.