1.1.
Anonymous Functions
Anonymous naming rules for name functions : identified by the LAMDBA keyword, the left side of the colon (:) indicates the parameter (a, b) that the function receives, and the right side of the colon (:) represents the function's return value (A+B). Because LAMDBA does not need to be named when it is created, it is called an anonymous function
Add = lambda A, b:a * bprint (Add (2, 3)) # 6
1.2.
functional programming and imperative programming
Our common programming paradigm is command-programmed (imperative programming), functional Programming
Common object-oriented programming is also a kind of imperative programming.
Imperative Programming is an abstraction for computer hardware , with variables (corresponding to storage units), assignment Statements (fetch, store instructions), expressions (memory references and arithmetic operations), and Control statement (jump instruction), in a word, the imperative program is a Von Neumann sequence of instructions .
Functional Programming is a mathematical-oriented abstraction that describes computation as an expression evaluation , in a word, a functional program is an expression .
Functional programming concerns the mapping of data, imperative programming cares about the steps to solve the problem
1.3.
Closed Package
definition: If a reference is made to a variable in an external scope (but not at the global scope) in an intrinsic function, then the intrinsic function is considered a closure (closure).
simply speaking , it's closures = function blocks (intrinsic functions) + (external) environment variables when defining intrinsic functions
# DEF outer (x): # When this x variable is passed in as a parameter, it is equivalent to the external variable of the intrinsic Function Def outer (): x = def inner (): print (x) return inner# yy = outer (+) # yy () The result of the execution is 100, the same reason XX = outer () # outer () has performed the completion of XX () # Why outer has been executed, But inner () can also fetch the x=10 value? # Closures (closure)! The inner of return in outer is a closure function with an environment variable of x. Outer () () # 19# inner () # name ' inner ' is not defined scope is local# print (x) # name ' x ' are not Defined Scope Local
Learning---Anonymous functions and closures in Python learning