1. 函数定义名称后的括号是存放参数的,可以存放多个参数
def studengInfo(name,age,city): print("The student name is:",name) print("The student age is:",age) print("The student city is:",city) print(studengInfo("Ann",22,"Beijing"))
结果:
The student name is: Ann
The student age is: 22
The student city is: Beijing
None (解释:返回None的原因是因为没有返回值)
2.形参与实参的:定义函数时的参数叫做形参,调用时叫做实参。
定义函数时,参数的个数尽量控制不超过5-6个。
3.带返回值的参数,调用函数时,函数运行结束后,会返回一个值
# 带返回的参数 def calculateTax(price,tax_rage): talTotal = price * tax_rage return talTotal print(calculateTax(6,2)) 结果: 12
4.函数的文档化
文档化的作用:让阅读函数的工程师,能够方便的理解函数的作用
函数文档化的位置(在函数名称:之后,函数代码块的第一行)
def calculateTax(price,tax_rage): "计算税费" talTotal = price * tax_rage return talTotal print(calculateTax.__doc__) print(calculateTax(6,2)) 结果: 计算税费 12