Return是指返回一个数值,一般在函数中应用较多

Print则是指把结果打印出来,显示在屏幕上

def sum(a,b):
    total=a+b
    print('函数内:',total)
    return total                            #函数返回任意值
print('函数外:',sum(10,20))          #打印整个函数运行的返回值

运行结果:
函数内: 30
函数外: 30

若是把return去掉的话:
def sum(a,b):
    total=a+b
    print('函数内:',total)
#整个函数内其实已经赋值,但是没有打印出来
print('函数外:',sum(10,20))    

运行结果:
函数内: 30
函数外: None
     
-1-_review

相关文章: