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

后端 未结 7 1704
死守一世寂寞
死守一世寂寞 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:03

    Major difference:

    Calling print will immediately make your program write out text for you to see. Use print when you want to show a value to a human.

    return is a keyword. When a return statement is reached, Python will stop the execution of the current function, sending a value out to where the function was called. Use return when you want to send a value from one point in your code to another.

    Using return changes the flow of the program. Using print does not.

提交回复
热议问题