
In this code:
# Function definition
def get_product(number1, number2):
result = number1 * number2
return result
# Get integer inputs from the user
n1 = int(input("Enter an integer: "))
n2 = int(input("Enter another integer: "))
# Get the total
total = get_product(n1, n2)
# Print the total
print(total)This line is where the get_product() function is called:
total = get_product(n1,n2)Here’s what’s happening: we're calling get_product() and passing it two arguments, n1 and n2. The function then runs, calculates the product, and returns a value. That returned value is what gets stored in the variable total.
Now let’s take another look at the function itself:
def get_product(n1,n2):
result = n1*n2
return resultThe line return result means the function will send back the value stored in result to wherever the function was called.
Without the return statement, the function would still calculate n1 * n2 and store it in result, but nothing would be passed back to the outside—so the rest of your code wouldn’t have access to the answer.
Note: The return statement is important because it allows you to take the result of a function and use it later in your program. For example, you could use the returned value in further calculations or display it.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer