How is returning the output of a function different from printing it?

后端 未结 7 1828
死守一世寂寞
死守一世寂寞 2020-11-21 11:23

In my previous question, Andrew Jaffe writes:

In addition to all of the other hints and tips, I think you\'re missing something crucial: your functio

7条回答
  •  误落风尘
    2020-11-21 12:20

    def add(x, y):
        return x+y
    

    That way it can then become a variable.

    sum = add(3, 5)
    
    print(sum)
    

    But if the 'add' function print the output 'sum' would then be None as action would have already taken place after it being assigned.

提交回复
热议问题