What is the purpose of the return statement?

后端 未结 13 2562
难免孤独
难免孤独 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 07:10

    Difference between "return" and "print" can also be found in the following example:

    RETURN:

    def bigger(a, b):
        if a > b:
            return a
        elif a 

    The above code will give correct results for all inputs.

    PRINT:

    def bigger(a, b):
        if a > b:
            print a
        elif a 

    NOTE: This will fail for many test cases.

    ERROR:

    ----  
    

    FAILURE: Test case input: 3, 8.

                Expected result: 8  
    

    FAILURE: Test case input: 4, 3.

                Expected result: 4  
    

    FAILURE: Test case input: 3, 3.

                Expected result: 3  
    

    You passed 0 out of 3 test cases

提交回复
热议问题