python function------various parameters

define a function and call

def MyFirstFunction():
    print("这是我创建的第一个函数!!!")
    print("我表示很鸡冻。。。。。")
    print("再次感谢CCTV,感谢TVB,感谢EDU.SRC")

insert image description here

def MySecoundFunction(name):
    print(name+"我爱你")

insert image description here

Formal and actual parameters

>>> def MyFirstFunction(name):

Open formal parameter (parameter)
'the name in the function definition process is called the formal parameter'

#Because Ta is just a form, indicating that it occupies a parameter position

The actual parameter (argument)
print('The passed in ' + name + ' is called the actual parameter, because Ta is the specific parameter value!')

>>> MyFirstFunction('小甲鱼')

The small turtle passed in is called an actual parameter, because Ta is a specific parameter value!
insert image description here

keyword arguments

def SaySome(name,words):
    print(name + '->' + words)

    
SaySome(words='让编程改变世界',name='小甲鱼')

insert image description here

default parameters

(that is, if the default value is given in the formal parameter, the default value will be output when the actual parameter is not given)
insert image description here

Gather parameters

insert image description here

functions and procedures

Functions: have a return value
Procedures are simple, special and have no return value

If there is a return value, the function returns the corresponding value; if not, it returns None
insert image description here

Strictly speaking, python only has functions and no procedures.

insert image description here

Multiple values ​​can be returned, or one by one

Guess you like

Origin blog.csdn.net/qq_53571321/article/details/122389944