一、函数的名称、参数和返回值
def bmi(height, weight):
return round(weight/(height*height),1)
print(bmi(1.6,44)) #17.2
round函数返回一个数值,该数值是按照指定的小数位数进行四舍五入运算的结果。
二、Docstring
def bmi(height, weight):
'''
计算BMI的值:
:param height: 1.6m
:param weight: 44kg
:return: weight/(height*height),保留一位小数
'''
return round(weight/(height*height),1)
print(bmi.__doc__)
print(round.__doc__)
print(bmi(1.6,44)) #17.2
print(__doc__) 输出文件开头注释的内容
三、参数(见上一节函数的参数)
def gongxi():
print('恭喜发财!')
gongxi() #恭喜发财!
def hello(name,type):
print(f"{