Python的函数可以有返回值,也可以没有返回值。函数需要先定义后调用,函数体中 return 语句的结果就是返回值。如果一个函数没有 reutrn 语句,其实它有一个隐含的 return 语句,返回值是 None,类型也是 'NoneType'。
例如
def showplus(x): print(x) return x + 1 num = showplus(6) add = num + 2 print(add)
输出结果为
6 9
隐含return的情况
def showplus(x): print(x) num = showplus(6) print(num) print(type(num))
输出结果
6 None <class 'NoneType'>
更多学习内容,请点击。
Copyright © 2019- huatuowenda.com 版权所有 湘ICP备2023022495号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务