Three forms of defined functions

Three forms of defined functions

1, no function parameter

When defining the function parameter is a function of an intermediary transfer member receives an external value, in fact, a variable name
is not the function parameters within parentheses stage, known as a function of no arguments. Note that: when no parameters defined, meaning when there is no need to call the incoming parameters.
If the function does not need to rely on an external body of the incoming code logic value, you have to be defined as a function of no arguments.

def func():
    print('hello nick')
    
func()  # hello nick

Second, there is a reference function

There are parameters in the function definition stage brackets, known to have a function parameter. Note that: when there is a reference definition, must also pass parameters means that calling.
If the function code logic relies on the external body of the incoming values, there have to be defined as a function parameter.

def sum_self(x, y):
    """求和"""
    res = x+y
    print(res)

sum_self(1,2)  # 3

Third, the empty function

When you know you need to achieve a certain function, but do not know how to use time code to achieve, you can temporarily empty write a function and then to implement other functions.

def func():
    pass

Guess you like

Origin www.cnblogs.com/Dr-wei/p/11871574.html