函数的返回值的特点:
1、函数的返回值没有类型的限制
2、函数的返回值没有数量的限制
3、返回多个值:多个返回值用逗号分隔,返回形式为元组形式。
def func(): print('from func') return 1,1.1,'hello',[1,2,3] res=func() print(res,type(res)) #from func #(1, 1.1, 'hello', [1, 2, 3]) <class 'tuple'>
若返回值只有一个的话,返回的就是原数值类型。
def func(): return 123 res=func() print(res,type(res)) #123 <class 'int'>
若没有返回return,返回值的内容为None
def func(): return pass res=func() print(res) #None
return除了有返回值的功能,还有结束函数执行的的功能
函数内可以有多个return,但只要执行一次,整个函数就立即结束,并且将return后的值返回
def func(): print(1) return print(2) return print(3) func() #1