Python study notes (function)

Function definition
The purpose of using the function: reduce the difficulty of programming and reduce code reuse.
Function definition: use def statement,

def <name>(<parameters>):
	<body>

Function name <name>: Any valid Python identifier
Parameter list <parameters>: Values ​​passed to it when calling the function The number of
parameters is greater than or equal to zero, multiple parameters are separated by commas
Form parameters: When defining a function, parentheses after the function name The variable in is referred to as "formal parameter" for short. The formal parameters are only valid inside the function.
Actual parameter: When calling the function, the variable in parentheses behind the function name, referred to as "real parameter".
Function body <body>: The code that is executed when the function is called, consists of one or more statements.
The general form of the function call: <name> (<parameters>)
return statement: End the function call and return the result to the caller.
The return statement is optional and can appear anywhere in the function body.
Without a return statement, the function returns control to the caller at the end of the function body.
Function interface: return value and parameters.
The main way for functions to pass information: pass information by means of function return values, and pass information by parameters.
Function return value
return statement: The program exits the function and returns to the place where the function was called.
The value returned by the return statement is passed to the calling program.
There are two forms of return value: return a value, return multiple values.

Published 48 original articles · Like 25 · Visit 2453

Guess you like

Origin blog.csdn.net/qq_43628959/article/details/97942269