二、函数的返回值
- 使用关键字return定义
>>> def my_function(param1, param2):
return param1** 2 + param2 ** 2
- 不同于C语言,python并不需要定义函数的返回值类型,如果没有返回值,则默认返回None
>>> def af():
print("This is a function with no return value")
>>> print(af())
This is a function with no return value
None
- 如果有多个返回值,则python默认以元组的形式打包返回
>>> def af():
return 1, 'a', [1]
>>> af()
(1, 'a', [1])

浙公网安备 33010602011771号