What is the purpose of the return statement?

后端 未结 13 2511
难免孤独
难免孤独 2020-11-21 06:28

What is the simple basic explanation of what the return statement is, how to use it in Python?

And what is the difference between it and the print state

13条回答
  •  走了就别回头了
    2020-11-21 06:57

    I think a really simple answer might be useful here:

    return makes the value (a variable, often) available for use by the caller (for example, to be stored by a function that the function using return is within). Without return, your value or variable wouldn't be available for the caller to store/re-use.

    print prints to the screen, but does not make the value or variable available for use by the caller.

    (Fully admitting that the more thorough answers are more accurate.)

提交回复
热议问题