python (Old Boys Feedback ------- full-stack function)

First, what is the function

There are also other functions, such as language called C function, Java is called the method.
Can improve the function of the application module, and the repetition rate of the code, such as we know Python provides a number of built-in libraries, such as print ().
But you can also create your own function, this is called a user-defined function.
** Definition: function refers to a collection of statements by a name (function name) package together, you want to perform this function, simply call the function name to its
characteristic **

Code duplication 1.
2. consistency
3. scalability

Second, create a function

2.1 Format

def keyword used python defined function, the following general format:
def function name (parameter list):
function body

def hello():
    print("hello world")

hello()#调用

2.2

- Function names must begin with an underscore or a letter, can contain any combination of letters, numbers, or underscores. You can not use any punctuation
- function names are case-sensitive.
- function name can not be a reserved word

2.3

In the form of parameters: the parameter defines the time function and the function body, aimed at receiving the function call arguments
actual parameters: Parameters passed to the function when calling the function, may be constants, variables, expressions, functions, passed shaped reference
distinction: the parameter is a virtual, do not take up memory space, allocating only variable parameter in the memory unit when invoked, the argument is a variable, the memory space occupied, one-way data transfer, arguments passed parameter. parameter argument can not pass

Third, the parameters of the function

3.1 required parameters

Be sure to have parameters passed to the function in the correct order, when the number of calls and declarations must be consistent

def f(name,age):
print('I am %s,I am %d'%(name,age))

f('alex',18)
f('alvin',16)

Guess you like

Origin www.cnblogs.com/hyxk/p/11372292.html
Recommended