KnowledgeBoat Logo

Computer Science

What is wrong with the following function definition ?

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

Python Functions

6 Likes

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.

Answered By

2 Likes


Related Questions