首先返回值可以是任意类型



如果有返回值,必须要用变量接收才有效果




python pools 带返回值 python有没有返回值_bc

python pools 带返回值 python有没有返回值_html_02

# def func():
#     a=111
#     b=[1,2,3]
#     return b
# ret=func()
# print(ret)


View Code


 

函数可以没有返回值
当不写return时候 一个函数的默认返回值为'None'




python pools 带返回值 python有没有返回值_bc

python pools 带返回值 python有没有返回值_html_02

# def func1():
#     a=999
#     b=[5,6,7]
#     return b
# ret=func1()
# print(ret)


View Code


return None的时候函数的返回值也是None(几乎不用)




python pools 带返回值 python有没有返回值_bc

python pools 带返回值 python有没有返回值_html_02

# def func2():
#     a=111
#     b=[1,2,3]
#     return None
# ret=func2()
# print(ret)


View Code


当只写一个return时候  返回值为None




python pools 带返回值 python有没有返回值_bc

python pools 带返回值 python有没有返回值_html_02

# def func3():
#     a=777
#     b=[5,6,7]
#     return
# ret=func3()
# print(ret)


View Code


 

return有结束函数的作用
一但return后,return后的代码不会执行




python pools 带返回值 python有没有返回值_bc

python pools 带返回值 python有没有返回值_html_02

# def func4():
#     print(3685)
#     return    #return有结束函数的作用
#     print(8888)
# func4()


View Code


 



返回一个值




python pools 带返回值 python有没有返回值_bc

python pools 带返回值 python有没有返回值_html_02

def func6():
    '''
    返回一个值
    '''
    return 111
    return 'abc'
    return['abc',222]
print(func6())


View Code


 



返回多个值




python pools 带返回值 python有没有返回值_bc

python pools 带返回值 python有没有返回值_html_02

# def func7():
#     '''
#     返回多个值
#     '''
#     a=123
#     b='DDD'
#     return a,b,[123]
# ret=func7()
# print(ret


View Code


函数的返回值有三种情况:
1.不写返回值
2.只写return与写return None一样

return的作用:结束一个函数的执行


函数的返回值不为 None,有返回值
return aaa 返回一个值 (一个变量)
return a,b 返回多个值 (多个变量),多个变量之间用逗号区分
接收:可以用一个变量接收,以元组的形式返回,也可以用多个变量接收,返回几个就用几个变量接收
函数要先定义后调用