return gives a function result back to the caller.
print shows a value, while return lets you store a result and use it in later calculations.
def calculate_total(price, quantity):
return price * quantity
total = calculate_total(250, 3)
print(total)The function returns 750, which is stored in total before print displays it.
Change one value or function call, then explain how the result changes.
Keep this in mind: Read the function definition and its calls before predicting the result.
def calculate_total(price, quantity):
return price * quantity
total = calculate_total(250, 3)
print(total)
# Change the inputs and use total againRun the example, then change one value and observe the result.
