Function basis - three forms defined functions

No-argument function

When defining the function parameter is a function of an intermediary transfer member receives an external value, in fact, a variable name

No phase function parameter in the brackets, the function is called with 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 nash')
    
func()  # hello nash


There are function parameters

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


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/suren-apan/p/11374799.html