def 函数名,小括号,参数,冒号,缩进函数体
- 空函数:(pass可以作为占位符,比如还没有想好怎么写函数的代码,可以放pass让代码运行起来)
def pop():
pass
- 参数检查:
def my_abs(x):
if not isinstance(x,(int,float)):
raise TypeError('bad operand type')
if x>=0:
return x
else:
return -x