What is the purpose of the return statement?

后端 未结 13 2828
难免孤独
难免孤独 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:51

    return is part of a function definition, while print outputs text to the standard output (usually the console).

    A function is a procedure accepting parameters and returning a value. return is for the latter, while the former is done with def.

    Example:

    def timestwo(x):
        return x*2
    

提交回复
热议问题