1. Nested functions
The function Body contains a complete function, which can also be called a sub-function
---------------------------- nested function scope problems ---------------------------
Scope :
The inner function can access the scope of the outer function.
An external function cannot access the scope of an intrinsic function.
# CODING:GBK def Test (m,n): def test1 (): Print ('hehe') return m+n return test1 ()print(Test (8,9))
2. anonymous function
# CODING:GBK Lambda x,y:x+yprint(func_name)print(func_name)
Equivalent to
def add (x, y):
Return X+y
The lambda Colon is preceded by a parameter, followed by a return result
Function name () represents the execution of a function
Difference:
Lambda returns a function name
The normal function returns the result
A = {'Lilei': 94,'Lily': 80,'Lucy': 75,'Hanmeimei': 90}a.items () dict_items ([('Lilei', 94), ('Lily', 80), ('Lucy', 75), ('Hanmeimei', 90)]) list (A.items ()) [('Lilei', 94), ('Lily', 80), ('Lucy', 75), ('Hanmeimei', 90)]sorted (A.items (), Key=LambdaX:x[1],reverse=True) [('Lilei', 94), ('Hanmeimei', 90), ('Lily', 80), ('Lucy', 75)]
Python function advanced