python and function calls

python function code that is repeated several times callable period, according to the python function, we can use functional programming, to reduce duplication of code.

In this section, a detailed description of the function of python, and python functional programming different, is a function definition DEF key, defined as a function,

The output is "Helllo World", see the following code:
DEF F1 ():
Print ( 'the Hello World')
after a good function definition, then how to call a function, and executes output of the internal function, and as a function of how to can output "Hello World" of?

Call function is also very simple, direct write the function name in parentheses, such as to call functions f1, call way: f1 (), it will output "Hello World" of

Information, see screenshots calls and output information:

 

As a function of it, there are parameters such as a definition of add () function, so that two numbers together, see Code:
DEF the Add (A, B):

return a + b
in the add () function, a, b are the parameters add a function, such a function is called a function of the form, add value when the function call given by (), is the actual parameters, see the results of execution of the function call:

In the function, each function has a return value is as add () function returns the value of a + b and the function returns a return value of the key, remember to function,

The return code is not executed, that after the return to perform the function execution will be terminated. If a function is not keyword return, letter

The return value is the number of None, as f1 () function, the return value that he is None, see return value after execution of the function:

 

Guess you like

Origin www.cnblogs.com/confidence-pearl/p/10979946.html