define a function and call
def MyFirstFunction():
print("这是我创建的第一个函数!!!")
print("我表示很鸡冻。。。。。")
print("再次感谢CCTV,感谢TVB,感谢EDU.SRC")
def MySecoundFunction(name):
print(name+"我爱你")
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!
keyword arguments
def SaySome(name,words):
print(name + '->' + words)
SaySome(words='让编程改变世界',name='小甲鱼')
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)
Gather parameters
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
Strictly speaking, python only has functions and no procedures.
Multiple values can be returned, or one by one