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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Ali Mammadov](https://secure.gravatar.com/avatar/784af22a4efa90a73471effb08655051?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Ali Mammadov
2,172 PointsReturning get_locations() instead of calling it
Why do we return get_locations() in the procedure of checking for duplicates? Why can't we just call this function? What difference will it make? What does "return some_awesome_function()" expression mean in python?
3 Answers
![Nicholas Hebb](https://secure.gravatar.com/avatar/856d4b67c1ca2a2307b3dcfd333c0719?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Nicholas Hebb
18,872 PointsIf you were to just call it without the return statement, the original monster, door, and start values would remain unchanged. Since "return monster, door, start" is the next line of the program, it would return those unchanged values.
By using "return get_locations()", the results of the recursive [1] call are returned.
[1] See http://en.wikipedia.org/wiki/Recursion_%28computer_science%29 for more info on recursion.
![Chris Freeman](https://uploads.teamtreehouse.com/production/profile-photos/1153532/micro_image.jpg)
Chris Freeman
Treehouse Moderator 68,425 PointsIn the line
return get_locations()
you are calling the function. The function call get_locations() is evaluated, then the results are returned. That line of code is a shortcut and has the same meaning as:
new_locations = get_locations()
return new_locations
Calling a function from within itself is a recursive call that is typically used to break a problem down into smaller chunks. In this usage, the problem isn't broken down but rather simply retried whole. There is a risk that if there were a typo that caused monster, door, or start to always have the same values, in recursion would become infinite. Python will detect this and report RuntimeError: Maximum recursion depth exceeded
Semantically, you're not actually returning the function – which is possible but uses a different syntax: leave off the parentheses.
Leaving off the parentheses is a common typo that is unfortunately valid syntax. For example, the condition in the line below always evaluates True because the method is_valid simply exists:
if form.is_valid:
The correct form would be
if form.is_valid():
![KAZUYA NAKAJIMA](https://uploads.teamtreehouse.com/production/profile-photos/128462/micro_20060120-200706.jpg)
KAZUYA NAKAJIMA
8,851 PointsVery informative thread. learned a lot from this thread.
Ali Mammadov
2,172 PointsAli Mammadov
2,172 PointsThanks for clearing it out!