# This is a learning note for the Liaoche teacher Python tutorial
1 , overview
We know that Python's built-in absolute value function is aBS ()
# Call the ABS () function to get a value
>>> ABS (-10)
10
# So, write only ABS itself?
>>> ABS
<built-in function abs>
Visible,ABS (-10) is a function call, and ABS is the function itself
1.1 , assigning a function to a variable
There are only two cases of assigning a function to a variable:
F=abs (-10)
Assigning the function itself to a variable, the variable can call the function at this point , that is, the variable can point to the function
F=abs
1.2 , the function name is also a variable
a function name is actually a variable that points to a function .
For ABS (), the function name ABS can be regarded as a variable. This means that you can assign other values to the ABS variable
ABS = 10
After the assignment. Call the ABS function again error
Note: As the ABS function is actually defined in the import builtins module, so to make changes to the ABS variable point in the other modules also take effect, to use the import builtins; builtins.abs =
2 , examples
A simple high-order function that calculates ABS (x) +abs (y)
#-*-Coding:utf-8-*-
def add (x, Y, f):
return f (x) + f (Y)
Print (Add ( -5, 6, ABS)) # the abs function is passed as an argument to the add function
Python Learning note __4.1 Zhang Gao function