#定义函数:
def myfunc(x):
if x >= 0:
return x
else:
return -x
#空函数:
def emptyfunc():
pass#占位符
#参数检查:
def checkfunc(x):
if not isinstance(x,(int,float)):
raise TypeError('must bi int or float type!')
if x >= 0:
return x
else:
return -x
print(checkfunc(5))#5
#返回多个值:
def price(x):
apple = x*2
banana = x*2.5
return apple,banana#函数返回多个值其实就是返回一个元组
print(price(2))#(4, 5.0)
08-08
305
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-06
281
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)