Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

What is the difference between return and result?

For example:

def yell(text): text = text.upper() number_of_characters = len(text) result = text + "!" * (number_of_characters // 4) print(result)

def split_check(total, number_of_people): cost_per_person = int(total / number_of_people) return cost_per_person

They are both calculating. Also in the bottom function did you even need to use return? Could you have just put print(cost_per_person) and gotten the same thing?

1 Answer

Someone may have a more in-depth and complex answer than this but I hope my answer to be concise.

return allows you to use data over and over again. Whereas print simply displays the data.

Here's a simple example:

def multiply(num1, num2):
    print(num1 * num2)

def multiply(num1, num2):
    return num1 * num2

The first function will simply display the value of one number multiplied by another.

The second function allows us to use the result of the multiplication in further calculations. For instance we could do something quite complex such as this

multiply ( multiply (3,4), multiply ( multiply (6,7), 8) )

The above would not be possible using the print function.