CBSE Class 12 Computer Science Question 79 of 103

Working with Functions — Question 12

Back to all questions
12
Question

Question 8

What is wrong with the following function definition ?

def addEm(x, y, z):  
    return x + y + z
    print("the answer is", x + y + z)
Answer

In the above function definition, the line print("the answer is", x + y + z) is placed after the return statement. In python, once a return statement is encountered, the function exits immediately, and any subsequent code in the function is not executed. Therefore, the print statement will never be executed.