Functions and procedures are functions that have no return value, both of which can be called
in python , the function return value is The value after return, and the procedure return value is None
Programming: Object-oriented, process-oriented, functional programming
Process-oriented programming: It is a small process defined by a def that is stitched together into a piece
Functional Programming:F =2x The mathematical function has an x, there will be a corresponding f - value such as:lisp, Erlang
For example , a function like the Python language is a true or false judgment, that is, an x does not necessarily correspond to an F
The following example: To calculate (1+2) *3-4
Traditional way:
var a =1+2;
var b =a*3;
var c=b-4;
Functional programming requires functions, which we can define as different functions, and then write the following styles:
var result =subtract (ultiply (Add (1+2), 3), 4)
This is functional programming.
Three great benefits of using functions:
reusability, consistency, and extensibility of code
returned value return
returns 0 values ( no return value ): Return to none
returns 1 values: returned as object (all data types in python are objects)
return multiple values : returns a tuple(tuple)
If this is: the return function now results in the address of the function
writing python files from Linux
Way:
First: Create a file vim test.py
Next: Write a program in the Vim file editor
Eg:def test2 (X,*args,**kwargs): print (x)
Print (args)
Print (Kwargs)
Test2 (" haha ", 4,sex = "F", name = "Zhangsan")
Then : Press:WQ Complete program writing
finally : results can be run by writing python test.py in terminal
The process of writing a function:
Define and write the function first
In writing the arguments of a function for delivery
Run the process: read the actual parameters first, and then pass the actual parameters to the function for processing
# Local Variables but for lists, dictionaries, collections, classes can be changed in local variables
School = "Oldboy" # global variable
def test4 (name):
Global School # The keyword allows you to change globals within a function
School = "Mage Linux"
Name = "Lisi" # Default: This function is the scope of the variable scope can be changed by the global keyword
Print (Name,school)
Name = "Zhangsan"
TEST4 (name)
Print (name)
Print (school)
Python's function learning