The basic function using python

Function definition:

Function is a piece with a specific function, reusable group of statements, with the function name and function call is represented by the function name.

Function is mainly used for two purposes: to reduce the difficulty of programming and code reuse.

python function is defined by using a reserved word def manner which syntax is as follows:

DEF <function name> (<parameter list>):

  <Function> The

  return <Back>

DEF HA ():
     Print ( " month: Mom, I want to eat roasted yams " )
 DEF of He ():
     Print ( " Month: Thank you, mom, mom nice " )
 DEF HH (name): 
    HA () 
    Print ( " mom: {}, two is not enough! " .format (name)) 
    of He ()     
    Print ( " mom: As long as obedient month, how many how many " ) 
HH ( " Moon " )
 Print ()

 <<< 
month: mom, I want to eat roasted yams 
mom: month, two is not enough! 
month: Thank you, mom, mom nice 
mom: so long as obedient month, how many how many


 *** Repl Closed ***

Call process functions:

Program calls a function requires the following four steps.

(1) calls the program be suspended at the call.

(2) copy the arguments to the function parameter when invoked.

(3) perform the function body statements.

(4) function call given by the end of the return value, the program returns to pause before the call to continue.

 

lambda functions, also known as anonymous functions. A simple definition, a function can be represented in a row, a function return type.

Syntax is as follows:

<Function name> lambda <parameter list> =: <expression>

f=lambda x,y:x*y
type(f)
print(f(3,4))

<<<
12

 

Keyword arguments:

Keyword parameters indicated by "** kwargs". Features: (1) a non-parameter required; (2) the number of parameters is not restricted; (3) was passed in must be the dictionary format.

def abc(**kwargs):
    print(kwargs)
abc(name='jw',age=20,time='2019-11-9')

<<<
{'name': 'jw', 'age': 20, 'time': '2019-11-9'}

***Repl Closed***

 

 

Added: a single function call must first define the call, call other functions within the function can be defined after the first call

Guess you like

Origin www.cnblogs.com/jackyfive/p/11826358.html