代码如下:
#返回2个值的加减乘除结果print("*"*10,"下面是fun1函数的输出结果:")def fun1(x,y): #定义函数fun1,参数分别是x,y result1=x+y result2=x-y result3=x*y result4=x/y return result1,result2,result3,result4print(fun1(12,4)) #打印函数fun1(参数是12,4)的返回值,函数的返回值必须使用print才能显示出来,最终返回的值是一个元祖print("*"*10,"下面是fun2函数的输出结果:")def fun2(x,y): #定义函数fun2,参数分别是x,y result1 = x + y result2 = x - y result3 = x * y result4 = x / y print(result1,result2,result3,result4)fun2(12,4) #调用函数fun2(参数是12,4)的结果,因为fun2最终有print关键字作为打印,所以这里就没有使用print,最终的结果是4个数字print("*"*10,"下面是fun3函数的输出结果:")def fun3(x,y): #定义函数fun2,参数分别是x,y result1 = x + y result2 = x - y result3 = x * y result4 = x / y print(result1,result2,result3,result4)print(fun3(12,4)) #调用函数fun3(参数是12,4)的结果,因为fun3最终有print关键字作为打印,但是这里使用print,最终的结果是4个数字,这是因为python中print函数需要返回值,函数体没有return关键字,最终输出None
代码运行结果如下:
********** 下面是fun1函数的输出结果:
(16, 8, 48, 3.0)
********** 下面是fun2函数的输出结果:
16 8 48 3.0
********** 下面是fun3函数的输出结果:
16 8 48 3.0
None
图片示例如下: